all repos — grayfriday @ 2a18706ca4952462e699c51b746e188970933d8d

blackfriday fork with a few changes

options to supress tab expansion or to expand tabs to 8 spaces instead of 4
Russ Ross russ@dixie.edu
Tue, 28 Jun 2011 10:58:10 -0600
commit

2a18706ca4952462e699c51b746e188970933d8d

parent

2f839dc39a59b7b94546e780af7322b0db3598c8

2 files changed, 23 insertions(+), 10 deletions(-)

jump to
M block.goblock.go

@@ -981,7 +981,10 @@

pre = i if data[beg] == '\t' { i = 1 - pre = TAB_SIZE + pre = TAB_SIZE_DEFAULT + if rndr.flags&EXTENSION_TAB_SIZE_EIGHT != 0 { + pre = TAB_SIZE_EIGHT + } } chunk := data[beg+i : end]
M markdown.gomarkdown.go

@@ -31,6 +31,8 @@ EXTENSION_STRIKETHROUGH

EXTENSION_LAX_HTML_BLOCKS EXTENSION_SPACE_HEADERS EXTENSION_HARD_LINE_BREAK + EXTENSION_NO_EXPAND_TABS + EXTENSION_TAB_SIZE_EIGHT ) // These are the possible flag values for the link renderer.

@@ -61,7 +63,10 @@ TABLE_ALIGNMENT_CENTER = (TABLE_ALIGNMENT_LEFT | TABLE_ALIGNMENT_RIGHT)

) // The size of a tab stop. -const TAB_SIZE = 4 +const ( + TAB_SIZE_DEFAULT = 4 + TAB_SIZE_EIGHT = 8 +) // These are the tags that are recognized as HTML block tags. // Any of these can be included in markdown text without special escaping.

@@ -210,6 +215,10 @@ // - normalize newlines

// - copy everything else func FirstPass(rndr *render, input []byte) []byte { var out bytes.Buffer + tab_size := TAB_SIZE_DEFAULT + if rndr.flags&EXTENSION_TAB_SIZE_EIGHT != 0 { + tab_size = TAB_SIZE_EIGHT + } beg, end := 0, 0 for beg < len(input) { // iterate over lines if end = isReference(rndr, input[beg:]); end > 0 {

@@ -222,10 +231,13 @@ }

// add the line body if present if end > beg { - expandTabs(&out, input[beg:end]) - } else { - out.WriteByte('\n') + if rndr.flags&EXTENSION_NO_EXPAND_TABS == 0 { + expandTabs(&out, input[beg:end], tab_size) + } else { + out.Write(input[beg:end]) + } } + out.WriteByte('\n') if end < len(input) && input[end] == '\r' { end++

@@ -449,7 +461,7 @@ }

// Replace tab characters with spaces, aligning to the next TAB_SIZE column. // always ends output with a newline -func expandTabs(out *bytes.Buffer, line []byte) { +func expandTabs(out *bytes.Buffer, line []byte, tab_size int) { // first, check for common cases: no tabs, or only tabs at beginning of line i, prefix := 0, 0 slowcase := false

@@ -466,11 +478,10 @@ }

// no need to decode runes if all tabs are at the beginning of the line if !slowcase { - for i = 0; i < prefix*TAB_SIZE; i++ { + for i = 0; i < prefix*tab_size; i++ { out.WriteByte(' ') } out.Write(line[prefix:]) - out.WriteByte('\n') return }

@@ -497,12 +508,11 @@

for { out.WriteByte(' ') column++ - if column%TAB_SIZE == 0 { + if column%tab_size == 0 { break } } i++ } - out.WriteByte('\n') }