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) {
|
func (w *HTMLWriter) WriteInlineBlock(b InlineBlock) {
|
||||||
content := w.blockContent(b.Name, b.Children)
|
content := w.blockContent(strings.ToUpper(b.Name), b.Children)
|
||||||
lang := strings.ToLower(b.Parameters[0])
|
switch b.Name {
|
||||||
w.WriteString(fmt.Sprintf("<div class=\"src src-inline src-%s\">\n%s\n</div>", lang, content))
|
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) {
|
func (w *HTMLWriter) WriteDrawer(d Drawer) {
|
||||||
|
|
|
@ -65,6 +65,7 @@ var footnoteRegexp = regexp.MustCompile(`^\[fn:([\w-]*?)(:(.*?))?\]`)
|
||||||
var statisticsTokenRegexp = regexp.MustCompile(`^\[(\d+/\d+|\d+%)\]`)
|
var statisticsTokenRegexp = regexp.MustCompile(`^\[(\d+/\d+|\d+%)\]`)
|
||||||
var latexFragmentRegexp = regexp.MustCompile(`(?s)^\\begin{(\w+)}(.*)\\end{(\w+)}`)
|
var latexFragmentRegexp = regexp.MustCompile(`(?s)^\\begin{(\w+)}(.*)\\end{(\w+)}`)
|
||||||
var inlineBlockRegexp = regexp.MustCompile(`src_(\w+)(\[(.*)\])?{(.*)}`)
|
var inlineBlockRegexp = regexp.MustCompile(`src_(\w+)(\[(.*)\])?{(.*)}`)
|
||||||
|
var inlineExportBlockRegexp = regexp.MustCompile(`@@(\w+):(.*?)@@`)
|
||||||
|
|
||||||
var timestampFormat = "2006-01-02 Mon 15:04"
|
var timestampFormat = "2006-01-02 Mon 15:04"
|
||||||
var datestampFormat = "2006-01-02 Mon"
|
var datestampFormat = "2006-01-02 Mon"
|
||||||
|
@ -85,6 +86,8 @@ func (d *Document) parseInline(input string) (nodes []Node) {
|
||||||
consumed, node = d.parseSubOrSuperScript(input, current)
|
consumed, node = d.parseSubOrSuperScript(input, current)
|
||||||
case '_':
|
case '_':
|
||||||
rewind, consumed, node = d.parseSubScriptOrEmphasisOrInlineBlock(input, current)
|
rewind, consumed, node = d.parseSubScriptOrEmphasisOrInlineBlock(input, current)
|
||||||
|
case '@':
|
||||||
|
consumed, node = d.parseInlineExportBlock(input, current)
|
||||||
case '*', '/', '+':
|
case '*', '/', '+':
|
||||||
consumed, node = d.parseEmphasis(input, current, false)
|
consumed, node = d.parseEmphasis(input, current, false)
|
||||||
case '=', '~':
|
case '=', '~':
|
||||||
|
@ -161,6 +164,13 @@ func (d *Document) parseInlineBlock(input string, start int) (int, int, Node) {
|
||||||
return 0, 0, nil
|
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) {
|
func (d *Document) parseExplicitLineBreakOrLatexFragment(input string, start int) (int, Node) {
|
||||||
switch {
|
switch {
|
||||||
case start+2 >= len(input):
|
case start+2 >= len(input):
|
||||||
|
|
|
@ -98,13 +98,20 @@ func (w *OrgWriter) WriteBlock(b Block) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *OrgWriter) WriteInlineBlock(b InlineBlock) {
|
func (w *OrgWriter) WriteInlineBlock(b InlineBlock) {
|
||||||
w.WriteString(b.Name + "_" + b.Parameters[0])
|
switch b.Name {
|
||||||
if len(b.Parameters) > 1 {
|
case "src":
|
||||||
w.WriteString("[" + strings.Join(b.Parameters[1:], " ") + "]")
|
w.WriteString(b.Name + "_" + b.Parameters[0])
|
||||||
|
if len(b.Parameters) > 1 {
|
||||||
|
w.WriteString("[" + strings.Join(b.Parameters[1:], " ") + "]")
|
||||||
|
}
|
||||||
|
w.WriteString("{")
|
||||||
|
WriteNodes(w, b.Children...)
|
||||||
|
w.WriteString("}")
|
||||||
|
case "export":
|
||||||
|
w.WriteString("@@" + b.Parameters[0] + ":")
|
||||||
|
WriteNodes(w, b.Children...)
|
||||||
|
w.WriteString("@@")
|
||||||
}
|
}
|
||||||
w.WriteString("{")
|
|
||||||
WriteNodes(w, b.Children...)
|
|
||||||
w.WriteString("}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *OrgWriter) WriteDrawer(d Drawer) {
|
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>
|
<li>
|
||||||
<p>
|
<p>
|
||||||
inline source blocks like <div class="src src-inline src-html">
|
inline source blocks like <div class="src src-inline src-html">
|
||||||
<div class="highlight-inline">
|
<h1>hello</h1>
|
||||||
<pre>
|
|
||||||
<h1>hello</h1>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</p>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<p>
|
||||||
|
inline export blocks <h1>hello</h1>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|
1
org/testdata/inline.org
vendored
1
org/testdata/inline.org
vendored
|
@ -9,6 +9,7 @@
|
||||||
- _underlined_ *bold* =verbatim= ~code~ +strikethrough+
|
- _underlined_ *bold* =verbatim= ~code~ +strikethrough+
|
||||||
- *bold string with an *asterisk inside*
|
- *bold string with an *asterisk inside*
|
||||||
- inline source blocks like src_html[:eval no]{<h1>hello</h1>}
|
- inline source blocks like src_html[:eval no]{<h1>hello</h1>}
|
||||||
|
- inline export blocks @@html:<h1>hello</h1>@@
|
||||||
- =multiline emphasis is
|
- =multiline emphasis is
|
||||||
supported - and respects MaxEmphasisNewLines (default: 1)=
|
supported - and respects MaxEmphasisNewLines (default: 1)=
|
||||||
/so this
|
/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+
|
- _underlined_ *bold* =verbatim= ~code~ +strikethrough+
|
||||||
- *bold string with an *asterisk inside*
|
- *bold string with an *asterisk inside*
|
||||||
- inline source blocks like src_html[:eval no]{<h1>hello</h1>}
|
- inline source blocks like src_html[:eval no]{<h1>hello</h1>}
|
||||||
|
- inline export blocks @@html:<h1>hello</h1>@@
|
||||||
- =multiline emphasis is
|
- =multiline emphasis is
|
||||||
supported - and respects MaxEmphasisNewLines (default: 1)=
|
supported - and respects MaxEmphasisNewLines (default: 1)=
|
||||||
/so this
|
/so this
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue