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:
Niklas Fasching 2021-07-20 22:33:28 +02:00
parent 0e68f1db40
commit c901c00166
6 changed files with 43 additions and 4 deletions

View file

@ -86,7 +86,7 @@ func New() *Configuration {
DefaultSettings: map[string]string{ DefaultSettings: map[string]string{
"TODO": "TODO | DONE", "TODO": "TODO | DONE",
"EXCLUDE_TAGS": "noexport", "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), Log: log.New(os.Stderr, "go-org: ", 0),
ReadFile: ioutil.ReadFile, ReadFile: ioutil.ReadFile,
@ -179,6 +179,7 @@ func (d *Document) Get(key string) string {
// - todo (export headline todo status) // - todo (export headline todo status)
// - pri (export headline priority) // - pri (export headline priority)
// - tags (export headline tags) // - 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 // see https://orgmode.org/manual/Export-settings.html for more information
func (d *Document) GetOption(key string) string { func (d *Document) GetOption(key string) string {
get := func(settings map[string]string) string { get := func(settings map[string]string) string {

View file

@ -311,7 +311,9 @@ func (w *HTMLWriter) WriteStatisticToken(s StatisticToken) {
} }
func (w *HTMLWriter) WriteLineBreak(l LineBreak) { func (w *HTMLWriter) WriteLineBreak(l LineBreak) {
w.WriteString(strings.Repeat("\n", l.Count)) if w.document.GetOption("ealb") == "nil" || !l.BetweenMultibyteCharacters {
w.WriteString(strings.Repeat("\n", l.Count))
}
} }
func (w *HTMLWriter) WriteExplicitLineBreak(l ExplicitLineBreak) { func (w *HTMLWriter) WriteExplicitLineBreak(l ExplicitLineBreak) {

View file

@ -7,6 +7,7 @@ import (
"strings" "strings"
"time" "time"
"unicode" "unicode"
"unicode/utf8"
) )
type Text struct { type Text struct {
@ -14,7 +15,10 @@ type Text struct {
IsRaw bool IsRaw bool
} }
type LineBreak struct{ Count int } type LineBreak struct {
Count int
BetweenMultibyteCharacters bool
}
type ExplicitLineBreak struct{} type ExplicitLineBreak struct{}
type StatisticToken struct{ Content string } type StatisticToken struct{ Content string }
@ -159,7 +163,9 @@ func (d *Document) parseLineBreak(input string, start int) (int, Node) {
i := start i := start
for ; i < len(input) && input[i] == '\n'; i++ { 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) { func (d *Document) parseInlineBlock(input string, start int) (int, int, Node) {

View 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
View 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

View 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