aboutsummaryrefslogtreecommitdiff
path: root/parser.go
diff options
context:
space:
mode:
Diffstat (limited to 'parser.go')
-rw-r--r--parser.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/parser.go b/parser.go
index 6912890..bf435f8 100644
--- a/parser.go
+++ b/parser.go
@@ -314,6 +314,30 @@ var _attrRef = map[string]string{
`zwsp`: htmlSymbolZeroWidthSpace,
}
+// preprocessBlockCode preprocess the content of block code, like "include::"
+// directive, and return the new content.
+func preprocessBlockCode(doc *Document, content []byte) (newContent []byte) {
+ var bbuf bytes.Buffer
+ var lines = bytes.Split(content, []byte{'\n'})
+ for _, line := range lines {
+ if bytes.HasPrefix(line, []byte(`include::`)) {
+ var elInclude = parseInclude(doc, line)
+ if elInclude != nil {
+ bbuf.Write(elInclude.content)
+ bbuf.WriteByte('\n')
+ continue
+ }
+ }
+ bbuf.Write(line)
+ bbuf.WriteByte('\n')
+ }
+
+ newContent = applySubstitutions(doc, bbuf.Bytes())
+ return newContent
+}
+
+// applySubstitutions scan the content and replace attribute reference "{}"
+// with its value, and character '<', '>', '&' with HTML symbol.
func applySubstitutions(doc *Document, content []byte) []byte {
var (
raw = bytes.TrimRight(content, " \n")