all repos — grayfriday @ b3c64946051e90924054f0ec721092dbfbcda1f2

blackfriday fork with a few changes

recognize fraction slash as well as regular slash to make fractions
Russ Ross russ@russross.com
Sun, 11 Mar 2012 16:10:42 -0600
commit

b3c64946051e90924054f0ec721092dbfbcda1f2

parent

82ba58501c306edf762b90c8579fb6923a6520b9

1 files changed, 8 insertions(+), 4 deletions(-)

jump to
M smartypants.gosmartypants.go

@@ -256,6 +256,7 @@

func smartNumberGeneric(out *bytes.Buffer, smrt *smartypantsData, previousChar byte, text []byte) int { if wordBoundary(previousChar) && len(text) >= 3 { // is it of the form digits/digits(word boundary)?, i.e., \d+/\d+\b + // note: check for regular slash (/) or fraction slash (⁄, 0x2044, or 0xe2 81 84 in utf-8) numEnd := 0 for len(text) > numEnd && isdigit(text[numEnd]) { numEnd++

@@ -264,15 +265,18 @@ if numEnd == 0 {

out.WriteByte(text[0]) return 0 } - if len(text) < numEnd+2 || text[numEnd] != '/' { + denStart := numEnd + 1 + if len(text) > numEnd+3 && text[numEnd] == 0xe2 && text[numEnd+1] == 0x81 && text[numEnd+2] == 0x84 { + denStart = numEnd + 3 + } else if len(text) < numEnd+2 || text[numEnd] != '/' { out.WriteByte(text[0]) return 0 } - denEnd := numEnd + 1 + denEnd := denStart for len(text) > denEnd && isdigit(text[denEnd]) { denEnd++ } - if denEnd == numEnd+1 { + if denEnd == denStart { out.WriteByte(text[0]) return 0 }

@@ -280,7 +284,7 @@ if len(text) == denEnd || wordBoundary(text[denEnd]) {

out.WriteString("<sup>") out.Write(text[:numEnd]) out.WriteString("</sup>&frasl;<sub>") - out.Write(text[numEnd+1 : denEnd]) + out.Write(text[denStart:denEnd]) out.WriteString("</sub>") return denEnd - 1 }