Implement inline export blocks
https://orgmode.org/manual/Quoting-HTML-tags.html
This commit is contained in:
parent
3018ace8d0
commit
4b56810a65
6 changed files with 42 additions and 14 deletions
|
@ -133,9 +133,16 @@ func (w *HTMLWriter) WriteBlock(b Block) {
|
|||
}
|
||||
|
||||
func (w *HTMLWriter) WriteInlineBlock(b InlineBlock) {
|
||||
content := w.blockContent(b.Name, b.Children)
|
||||
content := w.blockContent(strings.ToUpper(b.Name), b.Children)
|
||||
switch b.Name {
|
||||
case "src":
|
||||
lang := strings.ToLower(b.Parameters[0])
|
||||
w.WriteString(fmt.Sprintf("<div class=\"src src-inline src-%s\">\n%s\n</div>", lang, content))
|
||||
case "export":
|
||||
if strings.ToLower(b.Parameters[0]) == "html" {
|
||||
w.WriteString(content + "\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (w *HTMLWriter) WriteDrawer(d Drawer) {
|
||||
|
|
|
@ -65,6 +65,7 @@ var footnoteRegexp = regexp.MustCompile(`^\[fn:([\w-]*?)(:(.*?))?\]`)
|
|||
var statisticsTokenRegexp = regexp.MustCompile(`^\[(\d+/\d+|\d+%)\]`)
|
||||
var latexFragmentRegexp = regexp.MustCompile(`(?s)^\\begin{(\w+)}(.*)\\end{(\w+)}`)
|
||||
var inlineBlockRegexp = regexp.MustCompile(`src_(\w+)(\[(.*)\])?{(.*)}`)
|
||||
var inlineExportBlockRegexp = regexp.MustCompile(`@@(\w+):(.*?)@@`)
|
||||
|
||||
var timestampFormat = "2006-01-02 Mon 15:04"
|
||||
var datestampFormat = "2006-01-02 Mon"
|
||||
|
@ -85,6 +86,8 @@ func (d *Document) parseInline(input string) (nodes []Node) {
|
|||
consumed, node = d.parseSubOrSuperScript(input, current)
|
||||
case '_':
|
||||
rewind, consumed, node = d.parseSubScriptOrEmphasisOrInlineBlock(input, current)
|
||||
case '@':
|
||||
consumed, node = d.parseInlineExportBlock(input, current)
|
||||
case '*', '/', '+':
|
||||
consumed, node = d.parseEmphasis(input, current, false)
|
||||
case '=', '~':
|
||||
|
@ -161,6 +164,13 @@ func (d *Document) parseInlineBlock(input string, start int) (int, int, Node) {
|
|||
return 0, 0, nil
|
||||
}
|
||||
|
||||
func (d *Document) parseInlineExportBlock(input string, start int) (int, Node) {
|
||||
if m := inlineExportBlockRegexp.FindStringSubmatch(input[start:]); m != nil {
|
||||
return len(m[0]), InlineBlock{"export", m[1:2], d.parseRawInline(m[2])}
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (d *Document) parseExplicitLineBreakOrLatexFragment(input string, start int) (int, Node) {
|
||||
switch {
|
||||
case start+2 >= len(input):
|
||||
|
|
|
@ -98,6 +98,8 @@ func (w *OrgWriter) WriteBlock(b Block) {
|
|||
}
|
||||
|
||||
func (w *OrgWriter) WriteInlineBlock(b InlineBlock) {
|
||||
switch b.Name {
|
||||
case "src":
|
||||
w.WriteString(b.Name + "_" + b.Parameters[0])
|
||||
if len(b.Parameters) > 1 {
|
||||
w.WriteString("[" + strings.Join(b.Parameters[1:], " ") + "]")
|
||||
|
@ -105,6 +107,11 @@ func (w *OrgWriter) WriteInlineBlock(b InlineBlock) {
|
|||
w.WriteString("{")
|
||||
WriteNodes(w, b.Children...)
|
||||
w.WriteString("}")
|
||||
case "export":
|
||||
w.WriteString("@@" + b.Parameters[0] + ":")
|
||||
WriteNodes(w, b.Children...)
|
||||
w.WriteString("@@")
|
||||
}
|
||||
}
|
||||
|
||||
func (w *OrgWriter) WriteDrawer(d Drawer) {
|
||||
|
|
12
org/testdata/inline.html
vendored
12
org/testdata/inline.html
vendored
|
@ -44,12 +44,14 @@ links with slashes do not become <em>emphasis</em>: <a href="https://somelinksho
|
|||
<li>
|
||||
<p>
|
||||
inline source blocks like <div class="src src-inline src-html">
|
||||
<div class="highlight-inline">
|
||||
<pre>
|
||||
<h1>hello</h1>
|
||||
</pre>
|
||||
</div>
|
||||
<h1>hello</h1>
|
||||
</div>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
inline export blocks <h1>hello</h1>
|
||||
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
|
|
1
org/testdata/inline.org
vendored
1
org/testdata/inline.org
vendored
|
@ -9,6 +9,7 @@
|
|||
- _underlined_ *bold* =verbatim= ~code~ +strikethrough+
|
||||
- *bold string with an *asterisk inside*
|
||||
- inline source blocks like src_html[:eval no]{<h1>hello</h1>}
|
||||
- inline export blocks @@html:<h1>hello</h1>@@
|
||||
- =multiline emphasis is
|
||||
supported - and respects MaxEmphasisNewLines (default: 1)=
|
||||
/so this
|
||||
|
|
1
org/testdata/inline.pretty_org
vendored
1
org/testdata/inline.pretty_org
vendored
|
@ -9,6 +9,7 @@
|
|||
- _underlined_ *bold* =verbatim= ~code~ +strikethrough+
|
||||
- *bold string with an *asterisk inside*
|
||||
- inline source blocks like src_html[:eval no]{<h1>hello</h1>}
|
||||
- inline export blocks @@html:<h1>hello</h1>@@
|
||||
- =multiline emphasis is
|
||||
supported - and respects MaxEmphasisNewLines (default: 1)=
|
||||
/so this
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue