mirror of
https://github.com/daylinmorgan/bbansi.git
synced 2024-11-22 01:10:44 -06:00
refactor: templates I guess?
This commit is contained in:
parent
16356ad51f
commit
190cf82e6e
1 changed files with 6 additions and 6 deletions
|
@ -17,7 +17,7 @@ type
|
||||||
|
|
||||||
proc len(span: BbSpan): int = span.slice[1] - span.slice[0]
|
proc len(span: BbSpan): int = span.slice[1] - span.slice[0]
|
||||||
|
|
||||||
proc endSpan(bbs: var BbString) =
|
template endSpan(bbs: var BbString) =
|
||||||
if bbs.spans.len == 0: return
|
if bbs.spans.len == 0: return
|
||||||
if bbs.plain.len >= 1:
|
if bbs.plain.len >= 1:
|
||||||
bbs.spans[^1].slice[1] = bbs.plain.len-1
|
bbs.spans[^1].slice[1] = bbs.plain.len-1
|
||||||
|
@ -27,28 +27,28 @@ proc endSpan(bbs: var BbString) =
|
||||||
proc newSpan(bbs: var BbString, styles: seq[string] = @[]) =
|
proc newSpan(bbs: var BbString, styles: seq[string] = @[]) =
|
||||||
bbs.spans.add BbSpan(styles: styles, slice: [bbs.plain.len, 0])
|
bbs.spans.add BbSpan(styles: styles, slice: [bbs.plain.len, 0])
|
||||||
|
|
||||||
proc resetSpan(bbs: var BbString) =
|
template resetSpan(bbs: var BbString) =
|
||||||
bbs.endSpan
|
bbs.endSpan
|
||||||
bbs.newSpan
|
bbs.newSpan
|
||||||
|
|
||||||
proc closeLastStyle(bbs: var BbString) =
|
template closeLastStyle(bbs: var BbString) =
|
||||||
bbs.endSpan
|
bbs.endSpan
|
||||||
let newStyle = bbs.spans[^1].styles[0..^2] # drop the latest style
|
let newStyle = bbs.spans[^1].styles[0..^2] # drop the latest style
|
||||||
bbs.newSpan newStyle
|
bbs.newSpan newStyle
|
||||||
|
|
||||||
proc addToSpan(bbs: var BbString, pattern: string) =
|
template addToSpan(bbs: var BbString, pattern: string) =
|
||||||
let currStyl = bbs.spans[^1].styles
|
let currStyl = bbs.spans[^1].styles
|
||||||
bbs.endSpan
|
bbs.endSpan
|
||||||
bbs.newSpan currStyl & @[pattern]
|
bbs.newSpan currStyl & @[pattern]
|
||||||
|
|
||||||
proc closeStyle(bbs: var BbString, pattern: string) =
|
template closeStyle(bbs: var BbString, pattern: string) =
|
||||||
let style = pattern[1..^1].strip()
|
let style = pattern[1..^1].strip()
|
||||||
if style in bbs.spans[^1].styles:
|
if style in bbs.spans[^1].styles:
|
||||||
bbs.endSpan
|
bbs.endSpan
|
||||||
let newStyle = bbs.spans[^1].styles.filterIt(it != style) # use sets instead
|
let newStyle = bbs.spans[^1].styles.filterIt(it != style) # use sets instead
|
||||||
bbs.newSpan newStyle
|
bbs.newSpan newStyle
|
||||||
|
|
||||||
proc closeFinalSpan(bbs: var BbString) =
|
template closeFinalSpan(bbs: var BbString) =
|
||||||
if bbs.spans.len >= 1 and bbs.spans[^1].slice[1] == 0:
|
if bbs.spans.len >= 1 and bbs.spans[^1].slice[1] == 0:
|
||||||
bbs.endSpan
|
bbs.endSpan
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue