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/mv.vec': 'Pack / Unpack',
85 'svp64/appendix': 'SVP64 Appendix',
86 'sv/svp64/appendix': 'SVP64 Appendix',
87 'sv/svp64_quirks': 'SVP64 Quirks',
88 'openpower/isa/simplev': 'Simple-V pseudocode',
89 'opcode_regs_deduped': 'SVP64 Augmentation Table',
90 'sv/av_opcodes': 'Audio and Video Opcodes',
91 'av_opcodes': 'Audio and Video Opcodes',
92 'sv/vector_ops': 'SV Vector ops',
93 'sv/int_fp_mv': 'FP/Int Conversion ops',
94 'sv/bitmanip': 'Bitmanip ops',
95 'sv/cr_int_predication': 'CR Weird ops',
96 'cr_int_predication': 'CR Weird ops',
97 'sv/fclass': 'FP Class ops',
98 'sv/biginteger': 'Big Integer',
99 'sv/biginteger/analysis': 'Big Integer Analysis',
100 'isa/svfparith': 'Floating Point pseudocode',
101 'isa/svfixedarith': 'Fixed Point pseudocode',
102 'openpower/isa/branch': 'Branch pseudocode',
103 'openpower/transcendentals': 'Transcendentals',
105 if link
.startswith("ls") and link
[2].isdigit():
106 out
.write(" found RFC %s\n" % link
)
107 return [Link(['', [], []],
108 [Str("{RFC "+link
+"}")],
109 ['#%s' % link
, '']), Str(v
[find_brack
+2:])]
111 out
.write(" found %s\n" % lookups
[link
])
112 return [Link(['', [], []],
113 [Str("{"+lookups
[link
]+"}")],
114 ['#%s' % link
, '']), Str(v
[find_brack
+2:])]
116 link
, ref
= link
.split("|")
117 return [Link(['', [], []],
119 [ref
, '']), Str(v
[find_brack
+2:])]
121 out
.write(" link type %s\n" %
123 if k
== 'RawInline' and v
[0] == 'html':
124 if re
.fullmatch(r
"< *br */? *>", v
[1]):
125 return [RawInline('latex', r
'\\')]
126 if re
.fullmatch(r
"< *sup *>", v
[1]):
127 return [RawInline('latex', r
'\textsuperscript{')]
128 if re
.fullmatch(r
"< */ *sup *>", v
[1]):
129 return [RawInline('latex', '}')]
130 if re
.fullmatch(r
"< *sub *>", v
[1]):
131 return [RawInline('latex', r
'\textsubscript{')]
132 if re
.fullmatch(r
"< */ *sub *>", v
[1]):
133 return [RawInline('latex', '}')]
134 if re
.fullmatch(r
"< *small *>", v
[1]):
135 return [RawInline('latex', r
'{\small ')]
136 if re
.fullmatch(r
"< */ *small *>", v
[1]):
137 return [RawInline('latex', '}')]
140 if __name__
== "__main__":
141 toJSONFilter(inlinenotes
)