Add support for backtick instead of pre

main
Rob Muhlestein 1 year ago
parent f73eb98915
commit b6992b4430
No known key found for this signature in database
GPG Key ID: 7542BA4ED72E5D81

@ -69,7 +69,7 @@ func (s *Block) String() string { return string(s.V) }
// a BonzaiMark document. This simplicity and clarity of 4-space tokens
// far outweighs the advantages of alternatives (such as fences).
//
// PEGN Spefication
// PEGN Specification
//
// Grammar <-- Block*
// Block <-- Bulleted / Numbered / Verbatim / Paragraph
@ -173,6 +173,8 @@ var begBold = regexp.MustCompile(`^\*{2}\p{L}`)
var endBold = regexp.MustCompile(`^\p{L}\*{2}`)
var begItalic = regexp.MustCompile(`^\*\p{L}`)
var endItalic = regexp.MustCompile(`^\p{L}\*`)
var begCode = regexp.MustCompile(`^` + "`" + `\p{L}`)
var endCode = regexp.MustCompile(`^\p{L}` + "`")
// Emph renders BonzaiMark emphasis spans specifically for
// VT100-compatible terminals (which almost all are today):
@ -180,7 +182,8 @@ var endItalic = regexp.MustCompile(`^\p{L}\*`)
// *Italic*
// **Bold**
// ***BoldItalic***
// <under> (keeping brackets)
// <Under> (keeping brackets)
// `Code`
//
// See Mark for block formatting and term for terminal rendering.
func Emph[T string | []byte | []rune](buf T) string {
@ -256,6 +259,21 @@ func Emph[T string | []byte | []rune](buf T) string {
continue
}
// `Code`
if s.Match(begCode) > 0 {
nbuf = append(nbuf, []rune(term.Under)...)
for s.Scan() {
if s.Match(endCode) > 0 {
nbuf = append(nbuf, s.R)
nbuf = append(nbuf, []rune(term.Reset)...)
s.E++
break
}
nbuf = append(nbuf, s.R)
}
continue
}
nbuf = append(nbuf, s.R)
} // end main scan loop

@ -167,6 +167,16 @@ func ExampleEmph_italic() {
// * Italic *
}
func ExampleEmph_code() {
term.Under = `<code>`
term.Reset = `<reset>`
fmt.Println(Z.Emph("`Code`"))
fmt.Println(Z.Emph("` Code `"))
// Output:
// <code>Code<reset>
// ` Code `
}
func ExampleEmph_basics() {
// Emph observes the term escapes

Loading…
Cancel
Save