diff --git a/z/mark.go b/z/mark.go index 14321cb..c73182f 100644 --- a/z/mark.go +++ b/z/mark.go @@ -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*** -// (keeping brackets) +// (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 diff --git a/z/mark_test.go b/z/mark_test.go index a0e9b43..0d41c4a 100644 --- a/z/mark_test.go +++ b/z/mark_test.go @@ -167,6 +167,16 @@ func ExampleEmph_italic() { // * Italic * } +func ExampleEmph_code() { + term.Under = `` + term.Reset = `` + fmt.Println(Z.Emph("`Code`")) + fmt.Println(Z.Emph("` Code `")) + // Output: + // Code + // ` Code ` +} + func ExampleEmph_basics() { // Emph observes the term escapes