7 from pandocfilters
import (toJSONFilter
, RawInline
, Space
, Str
, walk
, Image
,
11 Pandoc filter for Markdown that converts most endnotes into
12 Pandoc's inline notes. If input notes had multiple paragraphs,
13 the paragraphs are joined by a space. But if an input note
14 had any blocks other than paragraphs, the note is left as is.
17 # inkscape -z sv/bridge_phy.svg --export-png=bridge.png
18 out
= open("/tmp/log.txt", "w")
21 def query(k
, v
, f
, meta
):
25 elif isinstance(v
, list):
26 if inlines
and k
== 'Para':
27 inlines
.append(Space())
32 def inlinenotes(k
, v
, f
, meta
):
33 out
.write("k v f meta %s %s %s %s\n" %
34 (repr(k
), repr(v
), repr(f
), repr(meta
)))
37 if k
== u
'Image' and f
== 'latex':
39 out
.write(" image %s\n" % (imgname
))
40 if imgname
.startswith("/"):
41 # use absolute paths so pandoc_img.py can be used in any directory
42 file_path
= os
.path
.abspath(__file__
)
43 openpower_path
= os
.path
.split(file_path
)[0]
44 wiki_path
= os
.path
.split(openpower_path
)[0]
45 imgname
= os
.path
.join(wiki_path
, imgname
.lstrip('/'))
46 png
= imgname
.replace(".svg", ".png")
47 png
= os
.path
.split(png
)[1]
48 png
= "tex_out/%s" % png
49 print(f
"converting {imgname} to {png}", file=sys
.stderr
)
50 subprocess
.run(["inkscape", "-z", "-C", imgname
,
51 "--export-png=%s" % png
],
52 stdout
=subprocess
.PIPE
)
55 if k
== 'Str' and f
== 'latex':
57 if not v
.startswith("[["):
59 find_brack
= v
.find(']]')
62 link
= v
[2:find_brack
]
63 out
.write(" link %s\n" % link
)
64 lookups
= {'sv': 'Scalable Vectors for Power ISA',
65 'SV|sv': 'Scalable Vectors for Power ISA',
66 'openpower/sv': 'Scalable Vectors for Power ISA',
67 'sv/overview': 'Overview Chapter',
68 'sv/vector_isa_comparison': 'Vector ISA Comparison',
69 'sv/comparison_table': 'ISA Comparison Table',
70 'sv/compliancy_levels': 'Compliancy Levels',
71 'sv/svp64': 'SVP64 Chapter',
72 'svp64': 'SVP64 Chapter',
74 'sv/normal': 'Arithmetic Mode',
75 'sv/ldst': 'Load/Store Mode',
76 'sv/cr_ops': 'Condition Register Fields Mode',
77 'sv/executive_summary': 'Exevutive Summary',
78 'sv/branches': 'Branch Mode',
79 'sv/setvl': 'setvl instruction',
80 'sv/svstep': 'svstep instruction',
81 'sv/remap': 'REMAP subsystem',
82 'sv/remap/appendix': 'REMAP Appendix',
83 'sv/mv.swizzle': 'Swizzle Move',
84 'sv/twin_butterfly': 'Twin Butterfly',
85 'sv/mv.vec': 'Pack / Unpack',
86 'svp64/appendix': 'SVP64 Appendix',
87 'sv/svp64/appendix': 'SVP64 Appendix',
88 'sv/svp64_quirks': 'SVP64 Quirks',
89 'openpower/isa/simplev': 'Simple-V pseudocode',
90 'opcode_regs_deduped': 'SVP64 Augmentation Table',
91 'sv/av_opcodes': 'Audio and Video Opcodes',
92 'av_opcodes': 'Audio and Video Opcodes',
93 'sv/vector_ops': 'SV Vector ops',
94 'sv/int_fp_mv': 'FP/Int Conversion ops',
95 'sv/bitmanip': 'Bitmanip ops',
96 'sv/cr_int_predication': 'CR Weird ops',
97 'cr_int_predication': 'CR Weird ops',
98 'sv/fclass': 'FP Class ops',
99 'sv/biginteger': 'Big Integer',
100 'sv/biginteger/analysis': 'Big Integer Analysis',
101 'isa/svfparith': 'Floating Point pseudocode',
102 'isa/svfixedarith': 'Fixed Point pseudocode',
103 'openpower/isa/branch': 'Branch pseudocode',
104 'openpower/transcendentals': 'Transcendentals',
106 if link
.startswith("ls") and link
[2].isdigit():
107 out
.write(" found RFC %s\n" % link
)
108 return [Link(['', [], []],
109 [Str("{RFC "+link
+"}")],
110 ['#%s' % link
, '']), Str(v
[find_brack
+2:])]
112 out
.write(" found %s\n" % lookups
[link
])
113 return [Link(['', [], []],
114 [Str("{"+lookups
[link
]+"}")],
115 ['#%s' % link
, '']), Str(v
[find_brack
+2:])]
117 link
, ref
= link
.split("|")
118 return [Link(['', [], []],
120 [ref
, '']), Str(v
[find_brack
+2:])]
122 out
.write(" link type %s\n" %
124 if k
== 'RawInline' and v
[0] == 'html':
125 if re
.fullmatch(r
"< *br */? *>", v
[1]):
126 return [RawInline('latex', r
'\\')]
127 if re
.fullmatch(r
"< *sup *>", v
[1]):
128 return [RawInline('latex', r
'\textsuperscript{')]
129 if re
.fullmatch(r
"< */ *sup *>", v
[1]):
130 return [RawInline('latex', '}')]
131 if re
.fullmatch(r
"< *sub *>", v
[1]):
132 return [RawInline('latex', r
'\textsubscript{')]
133 if re
.fullmatch(r
"< */ *sub *>", v
[1]):
134 return [RawInline('latex', '}')]
135 if re
.fullmatch(r
"< *small *>", v
[1]):
136 return [RawInline('latex', r
'{\small ')]
137 if re
.fullmatch(r
"< */ *small *>", v
[1]):
138 return [RawInline('latex', '}')]
141 if __name__
== "__main__":
142 toJSONFilter(inlinenotes
)