all repos — grayfriday @ f5892105afdc5ff17ccb1e9790fac094383e5cda

blackfriday fork with a few changes

Rework em-dash parsing

Em-dashes now render without the surrounding spaces. For example:
  'foo -- bar' -> 'foo—bar'

This is now typographically accurate without having to write ugly
plaintext without spaces.
Anirudh Oppiliappan x@icyphox.sh
Sun, 19 Jun 2022 18:17:38 +0530
commit

f5892105afdc5ff17ccb1e9790fac094383e5cda

parent

4c9bf9512682b995722660a4196c0013228e2049

1 files changed, 13 insertions(+), 6 deletions(-)

jump to
M smartypants.gosmartypants.go

@@ -188,19 +188,25 @@ out.WriteByte(text[0])

return 0 } -func (r *SPRenderer) smartDash(out *bytes.Buffer, previousChar byte, text []byte) int { - if len(text) >= 2 { - if text[1] == '-' { +func (r *SPRenderer) smartEmDash(out *bytes.Buffer, previousChar byte, text []byte) int { + if len(text) >= 3 { + if text[1] == '-' && text[2] == '-' && isspace(text[3]) { out.WriteString("—") - return 1 + return 3 } + } + out.WriteByte(text[0]) + return 0 +} + +func (r *SPRenderer) smartEnDash(out *bytes.Buffer, previousChar byte, text []byte) int { + if len(text) >= 2 { if wordBoundary(previousChar) && wordBoundary(text[1]) { out.WriteString("–") return 0 } } - out.WriteByte(text[0]) return 0 }

@@ -414,7 +420,8 @@ r.callbacks['\''] = r.smartSingleQuote

r.callbacks['('] = r.smartParens if flags&SmartypantsDashes != 0 { if flags&SmartypantsLatexDashes == 0 { - r.callbacks['-'] = r.smartDash + r.callbacks[' '] = r.smartEmDash + r.callbacks['-'] = r.smartEnDash } else { r.callbacks['-'] = r.smartDashLatex }