fork(330) download
  1. import sys
  2. import re
  3.  
  4. # on Python 3.5
  5.  
  6. '''
  7. v0.6 Jun. 22, 2018
  8. - conv_super_pre_notation() handles [vhdl]
  9. - conv_super_pre_notation() handles [verilog]
  10. v0.5 May, 29, 2018
  11. - add conv_tex()
  12. v0.4 Apr. 25, 2018
  13. - add conv_tableFormat()
  14. v0.3 Apr. 25, 2018
  15. - conv_super_pre_notation() takes cpp notation
  16. v0.2 Apr. 25, 2018
  17. - add conv_super_pre_notation()
  18. - add conv_sublist()
  19. v0.1 Apr. 24, 2018
  20. - sub list is converted to Markdown style
  21. '''
  22.  
  23.  
  24. def conv_tex(intxt):
  25. if r"[Tex:" in intxt or r"[tex:" in intxt:
  26. wrk = re.sub('\[Tex:', r'```math\r\n', intxt)
  27. wrk = re.sub('\[tex:', r'```math\r\n', wrk)
  28. wrk = re.sub(r']', r'\r\n```', wrk)
  29. return wrk
  30. return intxt
  31.  
  32.  
  33. def conv_sublist(astr):
  34. if "---" in astr:
  35. astr = astr.replace("---", SPACE4 + SPACE4 + "-")
  36. if "--" in astr:
  37. astr = astr.replace("--", SPACE4 + "-")
  38. return astr
  39.  
  40.  
  41. def conv_super_pre_notation(astr):
  42. astr = astr.replace(">||", "```")
  43. astr = astr.replace(">|cpp|", "```cpp")
  44. astr = astr.replace(">|c|", "```c")
  45. astr = astr.replace("||<", "```")
  46. astr = astr.replace(">|verilog|", "```verilog")
  47. astr = astr.replace(">|vhdl|", "```vhdl")
  48. return astr
  49.  
  50.  
  51. def getTableFormat(numVertical):
  52. wrk = "|"
  53. for loop in range(numVertical - 1): # -1: except for first
  54. wrk += ":-:|"
  55. return wrk
  56.  
  57.  
  58. def conv_tableFormat(astr):
  59. global countTbl
  60. if "|" in astr:
  61. countTbl += 1
  62. if countTbl == 2:
  63. num = astr.count('|')
  64. fmt = getTableFormat(num)
  65. return fmt + "\r\n" + astr
  66. else:
  67. countTbl = 0
  68. return astr
  69.  
  70. # read from stdin
  71. lines = sys.stdin.readlines()
  72.  
  73. SPACE4 = " "
  74.  
  75. countTbl = 0 # Table format counter
  76. for elem in lines:
  77. wrk = conv_sublist(elem)
  78. wrk = conv_super_pre_notation(wrk)
  79. wrk = conv_tableFormat(wrk)
  80. wrk = conv_tex(wrk)
  81. print(wrk, end='')
  82.  
Success #stdin #stdout 0.04s 9652KB
stdin
|A|B|C|
|A|B|C|
|A|B|C|
テスト
|A|B|C|
|A|B|C|
|A|B|C|

- A
-- B
--- C

>|cpp|
// some cpp program
||<

[Tex:Z_c = \frac{1}{2 \pi f C}]

[tex:Z_c = \frac{1}{\omega C}]

[[[AAA]]]
stdout
|A|B|C|
|:-:|:-:|:-:|
|A|B|C|
|A|B|C|
テスト
|A|B|C|
|:-:|:-:|:-:|
|A|B|C|
|A|B|C|

- A
    - B
        - C

```cpp
// some cpp program
```

```math
Z_c = \frac{1}{2 \pi f C}
```

```math
Z_c = \frac{1}{\omega C}
```

[[[AAA]]]