Add non-standard ealb (east asian line break) option
See pandoc: https://pandoc.org/MANUAL.html#extension-east_asian_line_breaks
This commit is contained in:
parent
0e68f1db40
commit
c901c00166
6 changed files with 43 additions and 4 deletions
|
@ -86,7 +86,7 @@ func New() *Configuration {
|
|||
DefaultSettings: map[string]string{
|
||||
"TODO": "TODO | DONE",
|
||||
"EXCLUDE_TAGS": "noexport",
|
||||
"OPTIONS": "toc:t <:t e:t f:t pri:t todo:t tags:t title:t",
|
||||
"OPTIONS": "toc:t <:t e:t f:t pri:t todo:t tags:t title:t ealb:nil",
|
||||
},
|
||||
Log: log.New(os.Stderr, "go-org: ", 0),
|
||||
ReadFile: ioutil.ReadFile,
|
||||
|
@ -179,6 +179,7 @@ func (d *Document) Get(key string) string {
|
|||
// - todo (export headline todo status)
|
||||
// - pri (export headline priority)
|
||||
// - tags (export headline tags)
|
||||
// - ealb (non-standard) (export with east asian line breaks / ignore line breaks between multi-byte characters)
|
||||
// see https://orgmode.org/manual/Export-settings.html for more information
|
||||
func (d *Document) GetOption(key string) string {
|
||||
get := func(settings map[string]string) string {
|
||||
|
|
|
@ -311,7 +311,9 @@ func (w *HTMLWriter) WriteStatisticToken(s StatisticToken) {
|
|||
}
|
||||
|
||||
func (w *HTMLWriter) WriteLineBreak(l LineBreak) {
|
||||
if w.document.GetOption("ealb") == "nil" || !l.BetweenMultibyteCharacters {
|
||||
w.WriteString(strings.Repeat("\n", l.Count))
|
||||
}
|
||||
}
|
||||
|
||||
func (w *HTMLWriter) WriteExplicitLineBreak(l ExplicitLineBreak) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
type Text struct {
|
||||
|
@ -14,7 +15,10 @@ type Text struct {
|
|||
IsRaw bool
|
||||
}
|
||||
|
||||
type LineBreak struct{ Count int }
|
||||
type LineBreak struct {
|
||||
Count int
|
||||
BetweenMultibyteCharacters bool
|
||||
}
|
||||
type ExplicitLineBreak struct{}
|
||||
|
||||
type StatisticToken struct{ Content string }
|
||||
|
@ -159,7 +163,9 @@ func (d *Document) parseLineBreak(input string, start int) (int, Node) {
|
|||
i := start
|
||||
for ; i < len(input) && input[i] == '\n'; i++ {
|
||||
}
|
||||
return i - start, LineBreak{i - start}
|
||||
_, beforeLen := utf8.DecodeLastRuneInString(input[:start])
|
||||
_, afterLen := utf8.DecodeRuneInString(input[i:])
|
||||
return i - start, LineBreak{i - start, beforeLen > 1 && afterLen > 1}
|
||||
}
|
||||
|
||||
func (d *Document) parseInlineBlock(input string, start int) (int, int, Node) {
|
||||
|
|
8
org/testdata/east_asian_line_breaks.html
vendored
Normal file
8
org/testdata/east_asian_line_breaks.html
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<p>
|
||||
Line breaks between multi-byte characters are omitted when the <code class="verbatim">ealb</code> option is set:</p>
|
||||
<ul>
|
||||
<li>中午吃啥</li>
|
||||
<li>something else
|
||||
中午吃啥
|
||||
something else</li>
|
||||
</ul>
|
11
org/testdata/east_asian_line_breaks.org
vendored
Normal file
11
org/testdata/east_asian_line_breaks.org
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
#+OPTIONS: ealb:t
|
||||
|
||||
Line breaks between multi-byte characters are omitted when the =ealb= option is set:
|
||||
|
||||
- 中午
|
||||
吃啥
|
||||
|
||||
- something else
|
||||
中午
|
||||
吃啥
|
||||
something else
|
11
org/testdata/east_asian_line_breaks.pretty_org
vendored
Normal file
11
org/testdata/east_asian_line_breaks.pretty_org
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
#+OPTIONS: ealb:t
|
||||
|
||||
Line breaks between multi-byte characters are omitted when the =ealb= option is set:
|
||||
|
||||
- 中午
|
||||
吃啥
|
||||
|
||||
- something else
|
||||
中午
|
||||
吃啥
|
||||
something else
|
Loading…
Add table
Add a link
Reference in a new issue