From 502ccd5e3f41f4fd1b3bfa1fad2c41785db1a7d1 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 5 Aug 2022 23:33:05 +0700 Subject: all: cleaning up codes Use raw string literal whenever possible. --- asciidoctor.go | 2 +- asciidoctor_test.go | 14 +- attribute_class.go | 2 +- attribute_entry.go | 10 +- author.go | 12 +- cell_format_test.go | 22 +-- column_format.go | 2 +- column_format_test.go | 8 +- document.go | 36 ++-- document_parser.go | 14 +- document_test.go | 34 ++-- document_title.go | 4 +- element.go | 92 ++++----- element_attribute.go | 16 +- element_attribute_test.go | 32 ++-- element_include.go | 2 +- element_table.go | 6 +- element_table_test.go | 52 +++--- element_test.go | 60 +++--- html_backend.go | 158 ++++++++-------- inline_parser.go | 18 +- inline_parser_test.go | 92 ++++----- parser.go | 464 +++++++++++++++++++++++----------------------- parser_test.go | 4 +- revision_test.go | 40 ++-- section_counters.go | 2 +- section_counters_test.go | 16 +- table_parser_test.go | 34 ++-- 28 files changed, 624 insertions(+), 624 deletions(-) diff --git a/asciidoctor.go b/asciidoctor.go index 6e68f84..6849811 100644 --- a/asciidoctor.go +++ b/asciidoctor.go @@ -6,7 +6,7 @@ package asciidoctor import "github.com/shuLhan/share/lib/math/big" const ( - Version = "0.3.0" + Version = `0.3.0` ) func init() { diff --git a/asciidoctor_test.go b/asciidoctor_test.go index 168607b..387c5ed 100644 --- a/asciidoctor_test.go +++ b/asciidoctor_test.go @@ -11,9 +11,9 @@ import ( ) const ( - outputCallHtmlWriteHeader = "htmlWriteHeader" - outputCallToHTML = "ToHTML" - outputCallToHTMLBody = "ToHTMLBody" + outputCallHtmlWriteHeader = `htmlWriteHeader` + outputCallToHTML = `ToHTML` + outputCallToHTMLBody = `ToHTMLBody` ) func TestData(t *testing.T) { @@ -28,17 +28,17 @@ func TestData(t *testing.T) { err error ) - listTData, err = test.LoadDataDir("testdata") + listTData, err = test.LoadDataDir(`testdata`) if err != nil { t.Fatal(err) } for _, tdata = range listTData { - inputCall = tdata.Flag["input_call"] - outputCall = tdata.Flag["output_call"] + inputCall = tdata.Flag[`input_call`] + outputCall = tdata.Flag[`output_call`] for inputName, inputContent = range tdata.Input { - subtestName = tdata.Name + "/" + inputName + subtestName = tdata.Name + `/` + inputName t.Run(subtestName, func(t *testing.T) { var ( diff --git a/attribute_class.go b/attribute_class.go index d3e1a57..6e694a4 100644 --- a/attribute_class.go +++ b/attribute_class.go @@ -34,5 +34,5 @@ func (aclass *attributeClass) replace(old, new string) { // String concat all the attribute class into string separated by single // space. func (aclass attributeClass) String() string { - return strings.Join(aclass, " ") + return strings.Join(aclass, ` `) } diff --git a/attribute_entry.go b/attribute_entry.go index 7d5d794..a4dd722 100644 --- a/attribute_entry.go +++ b/attribute_entry.go @@ -11,11 +11,11 @@ type AttributeEntry map[string]string func newAttributeEntry() AttributeEntry { return AttributeEntry{ - MetaNameGenerator: "asciidoctor-go " + Version, - metaNameSectIDs: "", - metaNameShowTitle: "", - metaNameTableCaption: "", - metaNameVersionLabel: "", + MetaNameGenerator: `asciidoctor-go ` + Version, + metaNameSectIDs: ``, + metaNameShowTitle: ``, + metaNameTableCaption: ``, + metaNameVersionLabel: ``, } } diff --git a/author.go b/author.go index 20ce292..57ccad8 100644 --- a/author.go +++ b/author.go @@ -36,21 +36,21 @@ func parseAuthor(raw string) (author *Author) { } } - names = strings.Split(raw, " ") + names = strings.Split(raw, ` `) if len(names) == 0 { return } var initials bytes.Buffer - author.FirstName = strings.ReplaceAll(names[0], "_", " ") + author.FirstName = strings.ReplaceAll(names[0], `_`, ` `) initials.WriteByte(author.FirstName[0]) if len(names) >= 2 { lastIdx = len(names) - 1 - author.LastName = strings.ReplaceAll(names[lastIdx], "_", " ") + author.LastName = strings.ReplaceAll(names[lastIdx], `_`, ` `) author.MiddleName = strings.ReplaceAll( - strings.Join(names[1:lastIdx], " "), "_", " ", + strings.Join(names[1:lastIdx], ` `), `_`, ` `, ) if len(author.MiddleName) > 0 { @@ -70,10 +70,10 @@ func (author *Author) FullName() string { sb.WriteString(author.FirstName) if len(author.MiddleName) > 0 { - sb.WriteString(" " + author.MiddleName) + sb.WriteString(` ` + author.MiddleName) } if len(author.LastName) > 0 { - sb.WriteString(" " + author.LastName) + sb.WriteString(` ` + author.LastName) } return sb.String() } diff --git a/cell_format_test.go b/cell_format_test.go index 117292a..3c33cd6 100644 --- a/cell_format_test.go +++ b/cell_format_test.go @@ -16,52 +16,52 @@ func TestParseCellFormat(t *testing.T) { } var cases = []testCase{{ - raw: "3*", + raw: `3*`, exp: &cellFormat{ ndupCol: 3, }, }, { - raw: "3+", + raw: `3+`, exp: &cellFormat{ nspanCol: 3, }, }, { - raw: ".2+", + raw: `.2+`, exp: &cellFormat{ nspanRow: 2, }, }, { - raw: "2.3+", + raw: `2.3+`, exp: &cellFormat{ nspanCol: 2, nspanRow: 3, }, }, { - raw: "^", + raw: `^`, exp: &cellFormat{ alignHor: colAlignMiddle, }, }, { - raw: ".<", + raw: `.<`, exp: &cellFormat{ alignVer: colAlignTop, }, }, { - raw: "3+^.^", + raw: `3+^.^`, exp: &cellFormat{ nspanCol: 3, alignHor: colAlignMiddle, alignVer: colAlignMiddle, }, }, { - raw: "2*>m", + raw: `2*>m`, exp: &cellFormat{ ndupCol: 2, alignHor: colAlignBottom, style: colStyleMonospaced, }, }, { - raw: ".3+^.>s", + raw: `.3+^.>s`, exp: &cellFormat{ nspanRow: 3, alignHor: colAlignMiddle, @@ -69,13 +69,13 @@ func TestParseCellFormat(t *testing.T) { style: colStyleStrong, }, }, { - raw: ".^l", + raw: `.^l`, exp: &cellFormat{ alignVer: colAlignMiddle, style: colStyleLiteral, }, }, { - raw: "v", + raw: `v`, exp: &cellFormat{ style: colStyleVerse, }, diff --git a/column_format.go b/column_format.go index b6ac9f4..52ac250 100644 --- a/column_format.go +++ b/column_format.go @@ -60,7 +60,7 @@ func newColumnFormat() *columnFormat { } func (f *columnFormat) htmlClasses() string { - return strings.Join(f.classes, " ") + return strings.Join(f.classes, ` `) } func (f *columnFormat) merge(other *columnFormat) { diff --git a/column_format_test.go b/column_format_test.go index b9f1111..ebb1277 100644 --- a/column_format_test.go +++ b/column_format_test.go @@ -18,14 +18,14 @@ func TestParseColumnFormat(t *testing.T) { } var cases = []testCase{{ - s: "3*", + s: `3*`, expNCols: 3, expFormat: &columnFormat{ isDefault: true, width: big.NewRat(1), }, }, { - s: "3*^", + s: `3*^`, expNCols: 3, expFormat: &columnFormat{ alignHor: colAlignMiddle, @@ -33,7 +33,7 @@ func TestParseColumnFormat(t *testing.T) { width: big.NewRat(1), }, }, { - s: "3*.^", + s: `3*.^`, expNCols: 3, expFormat: &columnFormat{ alignVer: colAlignMiddle, @@ -50,7 +50,7 @@ func TestParseColumnFormat(t *testing.T) { for _, c = range cases { gotNCols, gotFormat = parseColumnFormat(c.s) - test.Assert(t, c.s+" ncols", c.expNCols, gotNCols) + test.Assert(t, c.s+` ncols`, c.expNCols, gotNCols) test.Assert(t, c.s, c.expFormat, gotFormat) } } diff --git a/document.go b/document.go index 2fae03d..8b9d42e 100644 --- a/document.go +++ b/document.go @@ -17,9 +17,9 @@ import ( const ( defSectnumlevels = 3 defTOCLevel = 2 - defTOCTitle = "Table of Contents" + defTOCTitle = `Table of Contents` defTitleSeparator = ':' - defVersionPrefix = "version " + defVersionPrefix = `version ` ) // Document represent content of asciidoc that has been parsed. @@ -114,18 +114,18 @@ func Open(file string) (doc *Document, err error) { raw, err = os.ReadFile(file) if err != nil { - return nil, fmt.Errorf("Open %s: %w", file, err) + return nil, fmt.Errorf(`Open %s: %w`, file, err) } wd, err = os.Getwd() if err != nil { - return nil, fmt.Errorf("Open %s: %w", file, err) + return nil, fmt.Errorf(`Open %s: %w`, file, err) } doc = newDocument() doc.fpath = filepath.Join(wd, file) doc.file = file - doc.LastUpdated = fi.ModTime().Round(time.Second).Format("2006-01-02 15:04:05 Z0700") + doc.LastUpdated = fi.ModTime().Round(time.Second).Format(`2006-01-02 15:04:05 Z0700`) parse(doc, raw) @@ -304,7 +304,7 @@ func (doc *Document) registerAnchor(id, label string) string { for ok { // The ID is duplicate got.counter++ - id = fmt.Sprintf("%s_%d", id, got.counter) + id = fmt.Sprintf(`%s_%d`, id, got.counter) got, ok = doc.anchors[id] } doc.anchors[id] = &anchor{ @@ -359,9 +359,9 @@ func (doc *Document) unpackRawAuthor() { } v = doc.Attributes[metaNameEmail] if len(v) > 0 { - sb.WriteString(" <") + sb.WriteString(` <`) sb.WriteString(v) - sb.WriteString(">") + sb.WriteString(`>`) } v = sb.String() if len(v) == 0 { @@ -371,7 +371,7 @@ func (doc *Document) unpackRawAuthor() { } var ( - rawAuthors []string = strings.Split(doc.rawAuthors, ";") + rawAuthors []string = strings.Split(doc.rawAuthors, `;`) authorKey = MetaNameAuthor emailKey = metaNameEmail initialsKey = metaNameAuthorInitials @@ -395,7 +395,7 @@ func (doc *Document) unpackRawAuthor() { doc.Authors = append(doc.Authors, author) if len(doc.Authors) >= 2 { - sb.WriteString(", ") + sb.WriteString(`, `) } sb.WriteString(author.FullName()) @@ -408,15 +408,15 @@ func (doc *Document) unpackRawAuthor() { doc.Attributes[lastNameKey] = author.LastName // No continue, the first author have two keys, one is - // "author" and another is "author_1". + // `author` and another is `author_1`. } - authorKey = fmt.Sprintf("%s_%d", MetaNameAuthor, x+1) - emailKey = fmt.Sprintf("%s_%d", metaNameEmail, x+1) - initialsKey = fmt.Sprintf("%s_%d", metaNameAuthorInitials, x+1) - firstNameKey = fmt.Sprintf("%s_%d", metaNameFirstName, x+1) - middleNameKey = fmt.Sprintf("%s_%d", metaNameMiddleName, x+1) - lastNameKey = fmt.Sprintf("%s_%d", metaNameLastName, x+1) + authorKey = fmt.Sprintf(`%s_%d`, MetaNameAuthor, x+1) + emailKey = fmt.Sprintf(`%s_%d`, metaNameEmail, x+1) + initialsKey = fmt.Sprintf(`%s_%d`, metaNameAuthorInitials, x+1) + firstNameKey = fmt.Sprintf(`%s_%d`, metaNameFirstName, x+1) + middleNameKey = fmt.Sprintf(`%s_%d`, metaNameMiddleName, x+1) + lastNameKey = fmt.Sprintf(`%s_%d`, metaNameLastName, x+1) doc.Attributes[authorKey] = author.FullName() doc.Attributes[emailKey] = author.Email @@ -482,7 +482,7 @@ func (doc *Document) unpackRawTitle() { } // unpackTitleSeparator set the Title separator using the first character in -// meta attribute "title-separator" value. +// meta attribute `title-separator` value. func (doc *Document) unpackTitleSeparator() { var ( v string diff --git a/document_parser.go b/document_parser.go index 608b95c..2227ed2 100644 --- a/document_parser.go +++ b/document_parser.go @@ -581,11 +581,11 @@ func (docp *documentParser) parseHeader() { if len(line) == 0 { return } - if bytes.HasPrefix(line, []byte("////")) { + if bytes.HasPrefix(line, []byte(`////`)) { docp.parseIgnoreCommentBlock() continue } - if bytes.HasPrefix(line, []byte("//")) { + if bytes.HasPrefix(line, []byte(`//`)) { continue } if line[0] == ':' { @@ -629,13 +629,13 @@ func (docp *documentParser) parseIgnoreCommentBlock() { if !ok { return } - if bytes.HasPrefix(line, []byte("////")) { + if bytes.HasPrefix(line, []byte(`////`)) { return } } } -// parseListBlock parse block after list continuation "+" until we found +// parseListBlock parse block after list continuation `+` until we found // empty line or non-list line. func (docp *documentParser) parseListBlock() (el *element, line []byte) { var ok bool @@ -810,7 +810,7 @@ func (docp *documentParser) parseListDescription( continue } if docp.kind == elKindListOrderedItem { - line = docp.parseListOrdered(listItem, "", line, term) + line = docp.parseListOrdered(listItem, ``, line, term) continue } if docp.kind == elKindListUnorderedItem { @@ -999,7 +999,7 @@ func (docp *documentParser) parseListOrdered( parentListItem = parentListItem.parent } - line = docp.parseListOrdered(listItem, "", line, term) + line = docp.parseListOrdered(listItem, ``, line, term) continue } if docp.kind == elKindListUnorderedItem { @@ -1234,7 +1234,7 @@ func (docp *documentParser) parseListUnordered( parentListItem = parentListItem.parent } - line = docp.parseListOrdered(listItem, "", line, term) + line = docp.parseListOrdered(listItem, ``, line, term) continue } diff --git a/document_test.go b/document_test.go index c95aa7c..12a9439 100644 --- a/document_test.go +++ b/document_test.go @@ -17,12 +17,12 @@ func TestOpen(t *testing.T) { err error ) - doc, err = Open("testdata/test.adoc") + doc, err = Open(`testdata/test.adoc`) if err != nil { t.Fatal(err) } - fout, err = os.OpenFile("testdata/test.got.html", + fout, err = os.OpenFile(`testdata/test.got.html`, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { t.Fatal(err) @@ -44,38 +44,38 @@ func TestParse_document_title(t *testing.T) { var cases = []testCase{{ content: `= Main: sub`, exp: DocumentTitle{ - Main: "Main", - Sub: "sub", + Main: `Main`, + Sub: `sub`, sep: defTitleSeparator, }, - expString: "Main: sub", + expString: `Main: sub`, }, { // Without space after separator content: `= Main:sub`, exp: DocumentTitle{ - Main: "Main:sub", + Main: `Main:sub`, sep: defTitleSeparator, }, - expString: "Main:sub", + expString: `Main:sub`, }, { // With multiple separator after separator content: `= a: b: c`, exp: DocumentTitle{ - Main: "a: b", - Sub: "c", + Main: `a: b`, + Sub: `c`, sep: defTitleSeparator, }, - expString: "a: b: c", + expString: `a: b: c`, }, { // With custom separator. content: `:title-separator: x = Mainx sub`, exp: DocumentTitle{ - Main: "Main", - Sub: "sub", + Main: `Main`, + Sub: `sub`, sep: 'x', }, - expString: "Mainx sub", + expString: `Mainx sub`, }} var ( @@ -85,9 +85,9 @@ func TestParse_document_title(t *testing.T) { for _, c = range cases { got = Parse([]byte(c.content)) - test.Assert(t, "Main", c.exp.Main, got.Title.Main) - test.Assert(t, "Sub", c.exp.Sub, got.Title.Sub) - test.Assert(t, "sep", c.exp.sep, got.Title.sep) - test.Assert(t, "String", c.expString, got.Title.String()) + test.Assert(t, `Main`, c.exp.Main, got.Title.Main) + test.Assert(t, `Sub`, c.exp.Sub, got.Title.Sub) + test.Assert(t, `sep`, c.exp.sep, got.Title.sep) + test.Assert(t, `String`, c.expString, got.Title.String()) } } diff --git a/document_title.go b/document_title.go index e646a8a..9312fd4 100644 --- a/document_title.go +++ b/document_title.go @@ -16,10 +16,10 @@ type DocumentTitle struct { } // String return the combination of main and subtitle separated by colon or -// meta "title-separator" value. +// meta `title-separator` value. func (docTitle *DocumentTitle) String() string { if len(docTitle.Sub) > 0 { - return fmt.Sprintf("%s%c %s", docTitle.Main, docTitle.sep, docTitle.Sub) + return fmt.Sprintf(`%s%c %s`, docTitle.Main, docTitle.sep, docTitle.Sub) } return docTitle.Main } diff --git a/element.go b/element.go index e757669..46d045d 100644 --- a/element.go +++ b/element.go @@ -28,7 +28,7 @@ type element struct { table *elementTable // sectnums contain the current section numbers. - // It will be set only if attribute "sectnums" is on. + // It will be set only if attribute `sectnums` is on. sectnums *sectionCounters // The key and value for attribute (lineKindAttribute). @@ -64,18 +64,18 @@ func (el *element) getListOrderedClass() string { func (el *element) getListOrderedType() string { switch el.level { case 2: - return "a" + return `a` case 3: - return "i" + return `i` case 4: - return "A" + return `A` case 5: - return "I" + return `I` } - return "" + return `` } -// getVideoSource generate video full URL for HTML attribute "src". +// getVideoSource generate video full URL for HTML attribute `src`. func (el *element) getVideoSource() string { var ( u = new(url.URL) @@ -98,89 +98,89 @@ func (el *element) getVideoSource() string { } if isYoutube { - u.Scheme = "https" - u.Host = "www.youtube.com" - u.Path = "/embed/" + src + u.Scheme = `https` + u.Host = `www.youtube.com` + u.Path = `/embed/` + src - q = append(q, "rel=0") + q = append(q, `rel=0`) vstr, ok = el.Attrs[attrNameStart] if ok { - q = append(q, attrNameStart+"="+vstr) + q = append(q, attrNameStart+`=`+vstr) } vstr, ok = el.Attrs[attrNameEnd] if ok { - q = append(q, attrNameEnd+"="+vstr) + q = append(q, attrNameEnd+`=`+vstr) } for _, vstr = range el.options { switch vstr { case optNameAutoplay, optNameLoop: - q = append(q, vstr+"=1") + q = append(q, vstr+`=1`) case optVideoModest: - q = append(q, optVideoYoutubeModestbranding+"=1") + q = append(q, optVideoYoutubeModestbranding+`=1`) case optNameNocontrols: - q = append(q, optNameControls+"=0") - q = append(q, optVideoPlaylist+"="+src) + q = append(q, optNameControls+`=0`) + q = append(q, optVideoPlaylist+`=`+src) case optVideoNofullscreen: - q = append(q, optVideoFullscreen+"=0") - el.Attrs[optVideoNofullscreen] = "" + q = append(q, optVideoFullscreen+`=0`) + el.Attrs[optVideoNofullscreen] = `` } } vstr, ok = el.Attrs[attrNameTheme] if ok { - q = append(q, attrNameTheme+"="+vstr) + q = append(q, attrNameTheme+`=`+vstr) } vstr, ok = el.Attrs[attrNameLang] if ok { - q = append(q, attrNameYoutubeLang+"="+vstr) + q = append(q, attrNameYoutubeLang+`=`+vstr) } } else if isVimeo { - u.Scheme = "https" - u.Host = "player.vimeo.com" - u.Path = "/video/" + src + u.Scheme = `https` + u.Host = `player.vimeo.com` + u.Path = `/video/` + src for _, vstr = range el.options { switch vstr { case optNameAutoplay, optNameLoop: - q = append(q, vstr+"=1") + q = append(q, vstr+`=1`) } } vstr, ok = el.Attrs[attrNameStart] if ok { - fragment = "at=" + vstr + fragment = `at=` + vstr } } else { for _, vstr = range el.options { switch vstr { case optNameAutoplay, optNameLoop: - el.Attrs[optNameNocontrols] = "" - el.Attrs[vstr] = "" + el.Attrs[optNameNocontrols] = `` + el.Attrs[vstr] = `` } } vstr, ok = el.Attrs[attrNameStart] if ok { - fragment = "t=" + vstr + fragment = `t=` + vstr vstr, ok = el.Attrs[attrNameEnd] if ok { - fragment += "," + vstr + fragment += `,` + vstr } } else if vstr, ok = el.Attrs[attrNameEnd]; ok { - fragment = "t=0," + vstr + fragment = `t=0,` + vstr } if len(fragment) > 0 { - src = src + "#" + fragment + src = src + `#` + fragment } return src } - u.RawQuery = strings.Join(q, "&") + u.RawQuery = strings.Join(q, `&`) u.Fragment = fragment return u.String() @@ -222,7 +222,7 @@ func (el *element) WriteString(s string) { el.raw = append(el.raw, []byte(s)...) } -// addChild push the "child" to the list of current element's child. +// addChild push the `child` to the list of current element's child. func (el *element) addChild(child *element) { if child == nil { return @@ -346,7 +346,7 @@ func (el *element) parseBlockImage(doc *Document, line []byte) bool { src = applySubstitutions(doc, src) el.Attrs[attrNameSrc] = string(src) - attrs = bytes.Split(line[attrBegin+1:attrEnd], []byte(",")) + attrs = bytes.Split(line[attrBegin+1:attrEnd], []byte(`,`)) if el.Attrs == nil { el.Attrs = make(map[string]string) } @@ -376,7 +376,7 @@ func (el *element) parseBlockImage(doc *Document, line []byte) bool { el.Attrs[attrNameHeight] = string(attrs[2]) } } - kv = strings.SplitN(attr, "=", 2) + kv = strings.SplitN(attr, `=`, 2) if len(kv) != 2 { continue } @@ -384,8 +384,8 @@ func (el *element) parseBlockImage(doc *Document, line []byte) bool { val = strings.Trim(kv[1], `"`) switch key { case attrNameFloat, attrNameAlign, attrNameRole: - if val == "center" { - val = "text-center" + if val == `center` { + val = `text-center` } el.addRole(val) default: @@ -444,7 +444,7 @@ func (el *element) parseListDescriptionItem(line []byte) { c byte ) - label, x = indexUnescape(line, []byte("::")) + label, x = indexUnescape(line, []byte(`::`)) el.rawLabel.Write(label) line = line[x+2:] @@ -523,11 +523,11 @@ func (el *element) parseListUnorderedItem(line []byte) { checklist = line[x : x+3] sym string ) - if bytes.Equal(checklist, []byte("[ ]")) { + if bytes.Equal(checklist, []byte(`[ ]`)) { sym = symbolUnchecked - } else if bytes.Equal(checklist, []byte("[x]")) || - bytes.Equal(checklist, []byte("[X]")) || - bytes.Equal(checklist, []byte("[*]")) { + } else if bytes.Equal(checklist, []byte(`[x]`)) || + bytes.Equal(checklist, []byte(`[X]`)) || + bytes.Equal(checklist, []byte(`[*]`)) { sym = symbolChecked } if len(sym) != 0 { @@ -613,10 +613,10 @@ func (el *element) parseSection(doc *Document, isDiscrete bool) { } func (el *element) parseStyleClass(line []byte) { - line = bytes.Trim(line, "[]") + line = bytes.Trim(line, `[]`) var ( - parts = bytes.Split(line, []byte(".")) + parts = bytes.Split(line, []byte(`.`)) class []byte ) @@ -843,7 +843,7 @@ func (el *element) toHTML(doc *Document, w io.Writer) { label = anchor.label } } - fmt.Fprintf(w, "%s", href, label) + fmt.Fprintf(w, `%s`, href, label) case elKindMacroTOC: if doc.tocIsEnabled && doc.tocPosition == metaValueMacro { diff --git a/element_attribute.go b/element_attribute.go index 5b6de01..d08538d 100644 --- a/element_attribute.go +++ b/element_attribute.go @@ -33,12 +33,12 @@ func (ea *elementAttribute) addRole(role string) { func (ea *elementAttribute) htmlClasses() string { if len(ea.roles) == 0 { - return "" + return `` } - return strings.Join(ea.roles, " ") + return strings.Join(ea.roles, ` `) } -// parseElementAttribute parse list of attributes in between "[" "]". +// parseElementAttribute parse list of attributes in between `[` `]`. // // BLOCK_ATTRS = BLOCK_ATTR *("," BLOCK_ATTR) // @@ -141,13 +141,13 @@ func (ea *elementAttribute) parseNamedValue(prevc byte, str string) { } var ( - kv []string = strings.Split(str, "=") + kv []string = strings.Split(str, `=`) key = kv[0] val = strings.TrimSpace(kv[1]) ) if len(val) == 0 { - ea.Attrs[key] = "" + ea.Attrs[key] = `` return } if val[0] == '"' { @@ -158,7 +158,7 @@ func (ea *elementAttribute) parseNamedValue(prevc byte, str string) { } var ( - rawvals []string = strings.Split(val, ",") + rawvals []string = strings.Split(val, `,`) vals = make([]string, 0, len(rawvals)) v string @@ -213,14 +213,14 @@ func (ea *elementAttribute) setByPreviousChar(prevc byte, str string) { case styleSource: ea.Attrs[attrNameSource] = str default: - ea.Attrs[str] = "" + ea.Attrs[str] = `` } case 2: switch ea.style { case styleQuote, styleVerse: ea.Attrs[attrNameCitation] = str default: - ea.Attrs[str] = "" + ea.Attrs[str] = `` } } } diff --git a/element_attribute_test.go b/element_attribute_test.go index c7b99e8..ef543aa 100644 --- a/element_attribute_test.go +++ b/element_attribute_test.go @@ -16,42 +16,42 @@ func Test_parseElementAttribute(t *testing.T) { } var cases = []testCase{{ - raw: "", + raw: ``, }, { - raw: "[]", + raw: `[]`, }, { - raw: "[STYLE]", + raw: `[STYLE]`, exp: elementAttribute{ - rawStyle: "STYLE", + rawStyle: `STYLE`, }, }, { - raw: "[style#id]", + raw: `[style#id]`, exp: elementAttribute{ - ID: "id", - rawStyle: "style", + ID: `id`, + rawStyle: `style`, }, }, { raw: `[#id.role1.role2,options="opt1,opt2"]`, exp: elementAttribute{ - ID: "id", - roles: []string{"role1", "role2"}, - options: []string{"opt1", "opt2"}, + ID: `id`, + roles: []string{`role1`, `role2`}, + options: []string{`opt1`, `opt2`}, pos: 1, }, }, { raw: `[cols="3*,^"]`, exp: elementAttribute{ Attrs: map[string]string{ - attrNameCols: "3*,^", + attrNameCols: `3*,^`, }, }, }, { raw: `[quote, attribution]`, exp: elementAttribute{ Attrs: map[string]string{ - attrNameAttribution: "attribution", + attrNameAttribution: `attribution`, }, - rawStyle: "quote", + rawStyle: `quote`, style: styleQuote, pos: 1, }, @@ -59,10 +59,10 @@ func Test_parseElementAttribute(t *testing.T) { raw: `[quote, attribution, citation]`, exp: elementAttribute{ Attrs: map[string]string{ - attrNameAttribution: "attribution", - attrNameCitation: "citation", + attrNameAttribution: `attribution`, + attrNameCitation: `citation`, }, - rawStyle: "quote", + rawStyle: `quote`, style: styleQuote, pos: 2, }, diff --git a/element_include.go b/element_include.go index a12ef31..5821359 100644 --- a/element_include.go +++ b/element_include.go @@ -48,7 +48,7 @@ func parseInclude(doc *Document, line []byte) (el *elementInclude) { el.content, err = os.ReadFile(el.fpath) if err != nil { - log.Printf("parseInclude %q: %s", doc.file, err) + log.Printf(`parseInclude %q: %s`, doc.file, err) return nil } diff --git a/element_table.go b/element_table.go index ee389e4..2c0fb42 100644 --- a/element_table.go +++ b/element_table.go @@ -132,7 +132,7 @@ func (table *elementTable) initializeClassAndStyles(ea *elementAttribute) { continue } if v[len(v)-1] != '%' { - v += "%" + v += `%` } table.styles[k] = v withWidth = true @@ -246,7 +246,7 @@ func (table *elementTable) htmlStyle() string { ) for k, v = range table.styles { - fmt.Fprintf(&buf, "%s: %s;", k, v) + fmt.Fprintf(&buf, `%s: %s;`, k, v) } return buf.String() } @@ -269,7 +269,7 @@ func parseAttrCols(val string) (ncols int, formats []*columnFormat) { } var ( - rawFormat = strings.Split(val, ",") + rawFormat = strings.Split(val, `,`) format *columnFormat n int diff --git a/element_table_test.go b/element_table_test.go index 42c1bfe..c30e6f1 100644 --- a/element_table_test.go +++ b/element_table_test.go @@ -18,7 +18,7 @@ func TestParseAttrCols(t *testing.T) { } var cases = []testCase{{ - val: "3*", + val: `3*`, ncols: 3, formats: []*columnFormat{ newColumnFormat(), @@ -26,7 +26,7 @@ func TestParseAttrCols(t *testing.T) { newColumnFormat(), }, }, { - val: "3*^", + val: `3*^`, ncols: 3, formats: []*columnFormat{{ alignHor: colAlignMiddle, @@ -39,7 +39,7 @@ func TestParseAttrCols(t *testing.T) { width: big.NewRat(1), }}, }, { - val: "2*,^", + val: `2*,^`, ncols: 2, formats: []*columnFormat{{ width: big.NewRat(1), @@ -48,7 +48,7 @@ func TestParseAttrCols(t *testing.T) { width: big.NewRat(1), }}, }, { - val: "<,^,>", + val: `<,^,>`, ncols: 3, formats: []*columnFormat{{ alignHor: colAlignTop, @@ -61,7 +61,7 @@ func TestParseAttrCols(t *testing.T) { width: big.NewRat(1), }}, }, { - val: "3*.^", + val: `3*.^`, ncols: 3, formats: []*columnFormat{{ alignVer: colAlignMiddle, @@ -74,7 +74,7 @@ func TestParseAttrCols(t *testing.T) { width: big.NewRat(1), }}, }, { - val: "2*,.>", + val: `2*,.>`, ncols: 2, formats: []*columnFormat{{ width: big.NewRat(1), @@ -83,7 +83,7 @@ func TestParseAttrCols(t *testing.T) { width: big.NewRat(1), }}, }, { - val: ".<,.^,.>", + val: `.<,.^,.>`, ncols: 3, formats: []*columnFormat{{ alignVer: colAlignTop, @@ -96,7 +96,7 @@ func TestParseAttrCols(t *testing.T) { width: big.NewRat(1), }}, }, { - val: ".<,.^,^.>", + val: `.<,.^,^.>`, ncols: 3, formats: []*columnFormat{{ alignVer: colAlignTop, @@ -110,7 +110,7 @@ func TestParseAttrCols(t *testing.T) { width: big.NewRat(1), }}, }, { - val: "1,2,6", + val: `1,2,6`, ncols: 3, formats: []*columnFormat{{ width: big.NewRat(1), @@ -120,7 +120,7 @@ func TestParseAttrCols(t *testing.T) { width: big.NewRat(6), }}, }, { - val: "50,20,30", + val: `50,20,30`, ncols: 3, formats: []*columnFormat{{ width: big.NewRat(50), @@ -130,7 +130,7 @@ func TestParseAttrCols(t *testing.T) { width: big.NewRat(30), }}, }, { - val: ".<2,.^5,^.>3", + val: `.<2,.^5,^.>3`, ncols: 3, formats: []*columnFormat{{ alignVer: colAlignTop, @@ -144,7 +144,7 @@ func TestParseAttrCols(t *testing.T) { width: big.NewRat(3), }}, }, { - val: "h,m,s,e", + val: `h,m,s,e`, ncols: 4, formats: []*columnFormat{{ style: colStyleHeader, @@ -169,7 +169,7 @@ func TestParseAttrCols(t *testing.T) { for _, c = range cases { ncols, formats = parseAttrCols(c.val) - test.Assert(t, "ncols", c.ncols, ncols) + test.Assert(t, `ncols`, c.ncols, ncols) test.Assert(t, c.val, c.formats, formats) } } @@ -182,49 +182,49 @@ func TestParseToRawRows(t *testing.T) { } var cases = []testCase{{ - desc: "empty content", + desc: `empty content`, raw: ``, exp: make([][]byte, 1), }, { - desc: "empty content with no header", + desc: `empty content with no header`, raw: ` `, exp: make([][]byte, 2), }, { - desc: "header only", + desc: `header only`, raw: `A | B`, exp: [][]byte{ - []byte("A | B"), + []byte(`A | B`), }, }, { - desc: "without header", + desc: `without header`, raw: ` | A`, exp: [][]byte{ nil, - []byte("| A"), + []byte(`| A`), }, }, { - desc: "header and one row", + desc: `header and one row`, raw: `A | B | C`, exp: [][]byte{ - []byte("A"), - []byte("| B"), + []byte(`A`), + []byte(`| B`), nil, - []byte("| C"), + []byte(`| C`), }, }, { - desc: "with no header, consecutive rows", + desc: `with no header, consecutive rows`, raw: ` | A | B | C | D`, exp: [][]byte{ nil, - []byte("| A | B"), - []byte("| C | D"), + []byte(`| A | B`), + []byte(`| C | D`), }, }} diff --git a/element_test.go b/element_test.go index 58ce598..e252db7 100644 --- a/element_test.go +++ b/element_test.go @@ -19,9 +19,9 @@ func TestAdocNode_parseListDescriptionItem(t *testing.T) { } var cases = []testCase{{ - line: "CPU::", + line: `CPU::`, expLevel: 0, - expRawTerm: "CPU", + expRawTerm: `CPU`, }} var ( @@ -33,9 +33,9 @@ func TestAdocNode_parseListDescriptionItem(t *testing.T) { el = &element{} el.parseListDescriptionItem([]byte(c.line)) - test.Assert(t, "element.Level", c.expLevel, el.level) - test.Assert(t, "element.rawLabel", c.expRawTerm, el.rawLabel.String()) - test.Assert(t, "element.raw", c.expRaw, string(el.raw)) + test.Assert(t, `element.Level`, c.expLevel, el.level) + test.Assert(t, `element.rawLabel`, c.expRawTerm, el.rawLabel.String()) + test.Assert(t, `element.raw`, c.expRaw, string(el.raw)) } } @@ -49,35 +49,35 @@ func TestElement_parseListUnorderedItem(t *testing.T) { } var cases = []testCase{{ - desc: "With text", + desc: `With text`, line: []byte("* \t a"), expRaw: []byte("a\n"), expLevel: 1, }, { - desc: "With unchecked box, no text", - line: []byte("* [ ]"), + desc: `With unchecked box, no text`, + line: []byte(`* [ ]`), expRaw: []byte("[ ]\n"), expLevel: 1, }, { - desc: "With unchecked box", + desc: `With unchecked box`, line: []byte("* [ ] \t a"), expRaw: []byte("❏ a\n"), expRoles: []string{classNameChecklist}, expLevel: 1, }, { - desc: "With checked box, using 'x'", + desc: `With checked box, using 'x'`, line: []byte("* [x] \t a"), expRaw: []byte("✓ a\n"), expRoles: []string{classNameChecklist}, expLevel: 1, }, { - desc: "With checked box, using 'X'", + desc: `With checked box, using 'X'`, line: []byte("* [X] \t a"), expRaw: []byte("✓ a\n"), expRoles: []string{classNameChecklist}, expLevel: 1, }, { - desc: "With checked box, using '*'", + desc: `With checked box, using '*'`, line: []byte("* [*] \t a"), expRaw: []byte("✓ a\n"), expRoles: []string{classNameChecklist}, @@ -94,9 +94,9 @@ func TestElement_parseListUnorderedItem(t *testing.T) { el.raw = el.raw[:0] el.parseListUnorderedItem(c.line) - test.Assert(t, c.desc+" - level", c.expLevel, el.level) - test.Assert(t, c.desc+" - roles", c.expRoles, el.roles) - test.Assert(t, c.desc+" - raw", c.expRaw, el.raw) + test.Assert(t, c.desc+` - level`, c.expLevel, el.level) + test.Assert(t, c.desc+` - roles`, c.expRoles, el.roles) + test.Assert(t, c.desc+` - raw`, c.expRaw, el.raw) } } @@ -108,7 +108,7 @@ func TestAdocNode_postConsumeTable(t *testing.T) { } var cases = []testCase{{ - desc: "single row, multiple lines", + desc: `single row, multiple lines`, raw: "|A\n|B", exp: elementTable{ ncols: 2, @@ -122,7 +122,7 @@ func TestAdocNode_postConsumeTable(t *testing.T) { cells: []*tableCell{{ content: []byte("A\n"), }, { - content: []byte("B"), + content: []byte(`B`), }}, ncell: 2, }}, @@ -144,7 +144,7 @@ func TestAdocNode_postConsumeTable(t *testing.T) { hasHeader: false, }, }, { - desc: "with header", + desc: `with header`, raw: "A1|B1\n\n|A2\n|B2", exp: elementTable{ ncols: 2, @@ -156,16 +156,16 @@ func TestAdocNode_postConsumeTable(t *testing.T) { }, rows: []*tableRow{{ cells: []*tableCell{{ - content: []byte("A1"), + content: []byte(`A1`), }, { - content: []byte("B1"), + content: []byte(`B1`), }}, ncell: 2, }, { cells: []*tableCell{{ content: []byte("A2\n"), }, { - content: []byte("B2"), + content: []byte(`B2`), }}, ncell: 2, }}, @@ -187,7 +187,7 @@ func TestAdocNode_postConsumeTable(t *testing.T) { hasHeader: true, }, }, { - desc: "with multiple rows", + desc: `with multiple rows`, raw: "A|B|\n\n|r1c1\n|r1c2|\n\n|r2c1 | r2c2", exp: elementTable{ ncols: 3, @@ -199,39 +199,39 @@ func TestAdocNode_postConsumeTable(t *testing.T) { }, rows: []*tableRow{{ cells: []*tableCell{{ - content: []byte("A"), + content: []byte(`A`), }, { - content: []byte("B"), + content: []byte(`B`), }, { - content: []byte(""), + content: []byte(``), }}, ncell: 3, }, { cells: []*tableCell{{ content: []byte("r1c1\n"), }, { - content: []byte("r1c2"), + content: []byte(`r1c2`), }, { - content: []byte(""), + content: []byte(``), }}, ncell: 3, }}, formats: []*columnFormat{{ - width: big.NewRat("33.3333"), + width: big.NewRat(`33.3333`), classes: []string{ classNameTableBlock, classNameHalignLeft, classNameValignTop, }, }, { - width: big.NewRat("33.3333"), + width: big.NewRat(`33.3333`), classes: []string{ classNameTableBlock, classNameHalignLeft, classNameValignTop, }, }, { - width: big.NewRat("33.3334"), + width: big.NewRat(`33.3334`), classes: []string{ classNameTableBlock, classNameHalignLeft, diff --git a/html_backend.go b/html_backend.go index 51a905f..e631448 100644 --- a/html_backend.go +++ b/html_backend.go @@ -13,51 +13,51 @@ import ( ) const ( - classNameArticle = "article" - classNameHalignCenter = "halign-center" - classNameHalignLeft = "halign-left" - classNameHalignRight = "halign-right" - classNameListingBlock = "listingblock" - classNameLiteral = "literal" - classNameLiteralBlock = "literalblock" - classNameTableBlock = "tableblock" - classNameToc = "toc" - classNameToc2 = "toc2" - classNameTocLeft = "toc-left" - classNameTocRight = "toc-right" - classNameUlist = "ulist" - classNameValignBottom = "valign-bottom" - classNameValignMiddle = "valign-middle" - classNameValignTop = "valign-top" + classNameArticle = `article` + classNameHalignCenter = `halign-center` + classNameHalignLeft = `halign-left` + classNameHalignRight = `halign-right` + classNameListingBlock = `listingblock` + classNameLiteral = `literal` + classNameLiteralBlock = `literalblock` + classNameTableBlock = `tableblock` + classNameToc = `toc` + classNameToc2 = `toc2` + classNameTocLeft = `toc-left` + classNameTocRight = `toc-right` + classNameUlist = `ulist` + classNameValignBottom = `valign-bottom` + classNameValignMiddle = `valign-middle` + classNameValignTop = `valign-top` ) const ( - htmlSymbolAmpersand = "&" - htmlSymbolApostrophe = "’" - htmlSymbolBrokenVerticalBar = "¦" - htmlSymbolCopyright = "©" - htmlSymbolDegreeSign = "°" - htmlSymbolDoubleLeftArrow = "⇐" - htmlSymbolDoubleQuote = """ - htmlSymbolDoubleRightArrow = "⇒" - htmlSymbolEllipsis = "…" - htmlSymbolEmdash = "—" - htmlSymbolGreaterthan = ">" - htmlSymbolLeftDoubleQuote = "“" - htmlSymbolLeftSingleQuote = "‘" - htmlSymbolLessthan = "<" - htmlSymbolNonBreakingSpace = " " - htmlSymbolPlus = "+" - htmlSymbolRegistered = "®" - htmlSymbolRightDoubleQuote = "”" - htmlSymbolRightSingleQuote = "’" - htmlSymbolSingleLeftArrow = "←" - htmlSymbolSingleQuote = "'" - htmlSymbolSingleRightArrow = "→" - htmlSymbolThinSpace = " " - htmlSymbolTrademark = "™" - htmlSymbolWordJoiner = "⁠" - htmlSymbolZeroWidthSpace = "​" + htmlSymbolAmpersand = `&` + htmlSymbolApostrophe = `’` + htmlSymbolBrokenVerticalBar = `¦` + htmlSymbolCopyright = `©` + htmlSymbolDegreeSign = `°` + htmlSymbolDoubleLeftArrow = `⇐` + htmlSymbolDoubleQuote = `"` + htmlSymbolDoubleRightArrow = `⇒` + htmlSymbolEllipsis = `…` + htmlSymbolEmdash = `—` + htmlSymbolGreaterthan = `>` + htmlSymbolLeftDoubleQuote = `“` + htmlSymbolLeftSingleQuote = `‘` + htmlSymbolLessthan = `<` + htmlSymbolNonBreakingSpace = ` ` + htmlSymbolPlus = `+` + htmlSymbolRegistered = `®` + htmlSymbolRightDoubleQuote = `”` + htmlSymbolRightSingleQuote = `’` + htmlSymbolSingleLeftArrow = `←` + htmlSymbolSingleQuote = `'` + htmlSymbolSingleRightArrow = `→` + htmlSymbolThinSpace = ` ` + htmlSymbolTrademark = `™` + htmlSymbolWordJoiner = `⁠` + htmlSymbolZeroWidthSpace = `​` ) func htmlWriteBlockBegin(el *element, out io.Writer, addClass string) { @@ -69,13 +69,13 @@ func htmlWriteBlockBegin(el *element, out io.Writer, addClass string) { var ( classes string = el.htmlClasses() - c string = strings.TrimSpace(addClass + " " + classes) + c string = strings.TrimSpace(addClass + ` ` + classes) ) if len(c) > 0 { fmt.Fprintf(out, ` class="%s">`, c) } else { - fmt.Fprint(out, ">") + fmt.Fprint(out, `>`) } if !(el.isStyleAdmonition() || @@ -90,7 +90,7 @@ func htmlWriteBlockBegin(el *element, out io.Writer, addClass string) { } func htmlWriteBlockAdmonition(el *element, out io.Writer) { - htmlWriteBlockBegin(el, out, "admonitionblock") + htmlWriteBlockBegin(el, out, `admonitionblock`) fmt.Fprint(out, "\n\n\n
") @@ -116,32 +116,32 @@ func htmlWriteBlockAdmonition(el *element, out io.Writer) { func htmlWriteBlockAudio(el *element, out io.Writer) { var ( - optControls string = " controls" + optControls string = ` controls` src string = el.Attrs[attrNameSrc] optAutoplay string optLoop string ) - htmlWriteBlockBegin(el, out, "audioblock") + htmlWriteBlockBegin(el, out, `audioblock`) fmt.Fprintf(out, "\n
", attrValueContent) if libstrings.IsContain(el.options, optNameAutoplay) { - optAutoplay = " autoplay" + optAutoplay = ` autoplay` } if libstrings.IsContain(el.options, optNameNocontrols) { - optControls = "" + optControls = `` } if libstrings.IsContain(el.options, optNameLoop) { - optLoop = " loop" + optLoop = ` loop` } fmt.Fprintf(out, _htmlBlockAudio, src, optAutoplay, optControls, optLoop) } func htmlWriteBlockExample(doc *Document, el *element, out io.Writer) { - htmlWriteBlockBegin(el, out, "exampleblock") + htmlWriteBlockBegin(el, out, `exampleblock`) if len(el.rawTitle) > 0 { doc.counterExample++ fmt.Fprintf(out, "\n
Example %d. %s
", @@ -151,7 +151,7 @@ func htmlWriteBlockExample(doc *Document, el *element, out io.Writer) { } func htmlWriteBlockImage(doc *Document, el *element, out io.Writer) { - htmlWriteBlockBegin(el, out, "imageblock") + htmlWriteBlockBegin(el, out, `imageblock`) var ( src = el.Attrs[attrNameSrc] @@ -184,7 +184,7 @@ func htmlWriteBlockImage(doc *Document, el *element, out io.Writer) { } func htmlWriteBlockLiteral(el *element, out io.Writer) { - htmlWriteBlockBegin(el, out, "") + htmlWriteBlockBegin(el, out, ``) var ( source string @@ -193,7 +193,7 @@ func htmlWriteBlockLiteral(el *element, out io.Writer) { ) source, ok = el.Attrs[attrNameSource] if ok { - class = "language-" + source + class = `language-` + source fmt.Fprint(out, "\n
\n
")
 		fmt.Fprintf(out, `%s
`, class, source, el.raw) @@ -209,7 +209,7 @@ func htmlWriteBlockOpenBegin(el *element, out io.Writer) { } func htmlWriteBlockQuote(el *element, out io.Writer) { - htmlWriteBlockBegin(el, out, "quoteblock") + htmlWriteBlockBegin(el, out, `quoteblock`) fmt.Fprintf(out, "\n
\n%s", el.raw) } @@ -235,7 +235,7 @@ func htmlWriteBlockQuoteEnd(el *element, out io.Writer) { } func htmlWriteBlockSidebar(el *element, out io.Writer) { - htmlWriteBlockBegin(el, out, "sidebarblock") + htmlWriteBlockBegin(el, out, `sidebarblock`) fmt.Fprintf(out, "\n
", attrValueContent) if len(el.rawTitle) > 0 { fmt.Fprintf(out, "\n
%s
", attrValueTitle, @@ -244,12 +244,12 @@ func htmlWriteBlockSidebar(el *element, out io.Writer) { } func htmlWriteBlockVerse(el *element, out io.Writer) { - htmlWriteBlockBegin(el, out, "verseblock") + htmlWriteBlockBegin(el, out, `verseblock`) fmt.Fprintf(out, "\n
%s", attrValueContent, el.raw)
 }
 
 func htmlWriteBlockVerseEnd(el *element, out io.Writer) {
-	fmt.Fprint(out, "
") + fmt.Fprint(out, ``) var ( v string @@ -299,7 +299,7 @@ func htmlWriteBlockVideo(el *element, out io.Writer) { isVimeo = true } - htmlWriteBlockBegin(el, out, "videoblock") + htmlWriteBlockBegin(el, out, `videoblock`) fmt.Fprintf(out, "\n
", attrValueContent) @@ -311,14 +311,14 @@ func htmlWriteBlockVideo(el *element, out io.Writer) { optFullscreen, noFullscreen = el.Attrs[optVideoNofullscreen] if !noFullscreen { - optFullscreen = " allowfullscreen" + optFullscreen = ` allowfullscreen` } fmt.Fprintf(out, _htmlBlockVideoYoutube, width, height, src, optFullscreen) } else if isVimeo { fmt.Fprintf(out, _htmlBlockVideoVimeo, width, height, src) } else { var ( - optControls = " controls" + optControls = ` controls` optAutoplay string optLoop string @@ -332,13 +332,13 @@ func htmlWriteBlockVideo(el *element, out io.Writer) { } if libstrings.IsContain(el.options, optNameNocontrols) { - optControls = "" + optControls = `` } if libstrings.IsContain(el.options, optNameAutoplay) { - optAutoplay = " autoplay" + optAutoplay = ` autoplay` } if libstrings.IsContain(el.options, optNameLoop) { - optLoop = " loop" + optLoop = ` loop` } fmt.Fprintf(out, _htmlBlockVideo, src, width, @@ -378,9 +378,9 @@ func htmlWriteFooter(doc *Document, out io.Writer) { prefix, ok = doc.Attributes[metaNameVersionLabel] if ok && len(prefix) == 0 { - prefix = "Version " + prefix = `Version ` } else { - prefix = " " + prefix = ` ` } fmt.Fprintf(out, "\n%s%s
", prefix, doc.Revision.Number) @@ -422,8 +422,8 @@ func htmlWriteHeader(doc *Document, out io.Writer) { authorID = attrValueAuthor emailID = attrValueEmail } else { - authorID = fmt.Sprintf("%s%d", attrValueAuthor, x+1) - emailID = fmt.Sprintf("%s%d", attrValueEmail, x+1) + authorID = fmt.Sprintf(`%s%d`, attrValueAuthor, x+1) + emailID = fmt.Sprintf(`%s%d`, attrValueEmail, x+1) } fmt.Fprintf(out, "\n%s
", @@ -441,12 +441,12 @@ func htmlWriteHeader(doc *Document, out io.Writer) { if ok && len(prefix) == 0 { prefix = defVersionPrefix } else { - prefix = " " + prefix = ` ` } - sep = "" + sep = `` if len(doc.Revision.Date) > 0 { - sep = "," + sep = `,` } fmt.Fprintf(out, "\n%s%s%s", @@ -462,7 +462,7 @@ func htmlWriteHeader(doc *Document, out io.Writer) { } fmt.Fprint(out, "\n
") - if doc.tocIsEnabled && (doc.tocPosition == "" || + if doc.tocIsEnabled && (doc.tocPosition == `` || doc.tocPosition == metaValueAuto || doc.tocPosition == metaValueLeft || doc.tocPosition == metaValueRight) { @@ -473,16 +473,16 @@ func htmlWriteHeader(doc *Document, out io.Writer) { func htmlWriteInlineImage(el *element, out io.Writer) { var ( - classes = strings.TrimSpace("image " + el.htmlClasses()) + classes = strings.TrimSpace(`image ` + el.htmlClasses()) link string withLink bool ) - fmt.Fprintf(out, "", classes) + fmt.Fprintf(out, ``, classes) link, withLink = el.Attrs[attrNameLink] if withLink { - fmt.Fprintf(out, "", attrValueImage, link) + fmt.Fprintf(out, ``, attrValueImage, link) } var ( @@ -503,7 +503,7 @@ func htmlWriteInlineImage(el *element, out io.Writer) { height = fmt.Sprintf(` height="%s"`, height) } - fmt.Fprintf(out, "%q%s%s", src, alt, width, height) + fmt.Fprintf(out, `%q%s%s`, src, alt, width, height) if withLink { fmt.Fprint(out, ``) @@ -515,13 +515,13 @@ func htmlWriteInlineImage(el *element, out io.Writer) { func htmlWriteListDescription(el *element, out io.Writer) { var openTag string if el.isStyleQandA() { - htmlWriteBlockBegin(el, out, "qlist qanda") + htmlWriteBlockBegin(el, out, `qlist qanda`) openTag = "\n
    " } else if el.isStyleHorizontal() { - htmlWriteBlockBegin(el, out, "hdlist") + htmlWriteBlockBegin(el, out, `hdlist`) openTag = "\n" } else { - htmlWriteBlockBegin(el, out, "dlist") + htmlWriteBlockBegin(el, out, `dlist`) openTag = "\n
    " } diff --git a/inline_parser.go b/inline_parser.go index 5fec3b3..62287bf 100644 --- a/inline_parser.go +++ b/inline_parser.go @@ -159,7 +159,7 @@ func (pi *inlineParser) do() { } if pi.nextc == '*' { if pi.parseFormatUnconstrained( - []byte("**"), + []byte(`**`), elKindUnconstrainedBold, elKindTextBold, styleTextBold) { @@ -176,7 +176,7 @@ func (pi *inlineParser) do() { } if pi.nextc == '_' { if pi.parseFormatUnconstrained( - []byte("__"), + []byte(`__`), elKindUnconstrainedItalic, elKindTextItalic, styleTextItalic) { @@ -365,7 +365,7 @@ func (pi *inlineParser) do() { isReplaced = true } } else if len(vbytes) == 2 { - if bytes.Equal(vbytes, []byte("TM")) { + if bytes.Equal(vbytes, []byte(`TM`)) { pi.current.WriteString(htmlSymbolTrademark) isReplaced = true } @@ -417,7 +417,7 @@ func (pi *inlineParser) parseCrossRef() bool { idx int ) - raw, idx = indexUnescape(raw, []byte(">>")) + raw, idx = indexUnescape(raw, []byte(`>>`)) if idx < 0 { return false } @@ -430,7 +430,7 @@ func (pi *inlineParser) parseCrossRef() bool { parts [][]byte ) - parts = bytes.Split(raw, []byte(",")) + parts = bytes.Split(raw, []byte(`,`)) href = string(parts[0]) if len(parts) >= 2 { label = string(bytes.TrimSpace(parts[1])) @@ -513,7 +513,7 @@ func (pi *inlineParser) parseInlineIDShort() bool { ) // Check if we have term at the end. - id, idx = indexUnescape(raw, []byte("]#")) + id, idx = indexUnescape(raw, []byte(`]#`)) if idx < 0 { return false } @@ -528,7 +528,7 @@ func (pi *inlineParser) parseInlineIDShort() bool { return false } - stringID = pi.doc.registerAnchor(string(id), "") + stringID = pi.doc.registerAnchor(string(id), ``) el = &element{ elementAttribute: elementAttribute{ @@ -736,7 +736,7 @@ func (pi *inlineParser) parseMacro() bool { } switch name { - case "": + case ``: return false case macroFTP, macroHTTPS, macroHTTP, macroIRC, macroLink, macroMailto: el = pi.parseURL(name) @@ -859,7 +859,7 @@ func (pi *inlineParser) parsePassthroughTriple() bool { ) // Check if we have "+++" at the end. - raw, idx = indexUnescape(raw, []byte("+++")) + raw, idx = indexUnescape(raw, []byte(`+++`)) if idx >= 0 { el = &element{ kind: elKindPassthroughTriple, diff --git a/inline_parser_test.go b/inline_parser_test.go index 9da5a93..c26b209 100644 --- a/inline_parser_test.go +++ b/inline_parser_test.go @@ -62,22 +62,22 @@ func TestInlineParser_parseAttrRef(t *testing.T) { var _testDoc = &Document{ Attributes: map[string]string{ - "x": "https://kilabit.info", + `x`: `https://kilabit.info`, }, } var cases = []testCase{{ - content: "A {x}[*B*] C", + content: `A {x}[*B*] C`, exp: `A B C`, }, { - content: "A {x }[*B*] C", + content: `A {x }[*B*] C`, exp: `A B C`, }, { - content: "A {x }*B* C", + content: `A {x }*B* C`, exp: `A https://kilabit.info*B* C`, }, { - content: "A {y }*B* C", - exp: "A {y }B C", + content: `A {y }*B* C`, + exp: `A {y }B C`, }} var ( @@ -110,26 +110,26 @@ func TestInlineParser_parseCrossReference(t *testing.T) { var _testDoc = &Document{ anchors: map[string]*anchor{ - "x": &anchor{ - label: "X y", + `x`: &anchor{ + label: `X y`, }, }, titleID: map[string]string{ - "X y": "x", + `X y`: `x`, }, } var cases = []testCase{{ - content: "A <>", + content: `A <>`, exp: `A X y`, }, { - content: "A <>", + content: `A <>`, exp: `A Label`, }, { - content: "A <>", + content: `A <>`, exp: `A X y`, }, { - content: "A <>", + content: `A <>`, exp: `A Label`, }} @@ -166,29 +166,29 @@ func TestInlineParser_parseFormat(t *testing.T) { } var cases = []testCase{{ - content: "_A_B", - exp: "_A_B", + content: `_A_B`, + exp: `_A_B`, }, { - content: "_A_ B", - exp: "A B", + content: `_A_ B`, + exp: `A B`, }, { - content: "_A _B", - exp: "_A _B", + content: `_A _B`, + exp: `_A _B`, }, { - content: "*A*B", - exp: "*A*B", + content: `*A*B`, + exp: `*A*B`, }, { - content: "*A* B", - exp: "A B", + content: `*A* B`, + exp: `A B`, }, { - content: "*A *B", - exp: "*A *B", + content: `*A *B`, + exp: `*A *B`, }, { content: "`A`B", exp: "`A`B", }, { content: "`A` B", - exp: "A B", + exp: `A B`, }, { content: "`A `B", exp: "`A `B", @@ -231,23 +231,23 @@ func TestInlineParser_parseFormatUnconstrained(t *testing.T) { } var cases = []testCase{{ - content: "__A__B", - exp: "AB", + content: `__A__B`, + exp: `AB`, }, { - content: "__A *B*__", - exp: "A B", + content: `__A *B*__`, + exp: `A B`, }, { - content: "__A _B_ C__", - exp: "A B C", + content: `__A _B_ C__`, + exp: `A B C`, }, { - content: "__A B_ C__", - exp: "A B_ C", + content: `__A B_ C__`, + exp: `A B_ C`, }, { - content: "__A *B*_", - exp: "_A B", + content: `__A *B*_`, + exp: `_A B`, }, { - content: "_A *B*__", - exp: "A B_", + content: `_A *B*__`, + exp: `A B_`, }} var ( @@ -724,20 +724,20 @@ func TestInlineParser_parseSuperscript(t *testing.T) { } var cases = []testCase{{ - content: "A^B^C", - exp: "ABC", + content: `A^B^C`, + exp: `ABC`, }, { - content: "A^B ^C", - exp: "A^B ^C", + content: `A^B ^C`, + exp: `A^B ^C`, }, { - content: "A^ B^C", - exp: "A^ B^C", + content: `A^ B^C`, + exp: `A^ B^C`, }, { content: `A\^B^C`, - exp: "A^B^C", + exp: `A^B^C`, }, { content: `A^B\^C`, - exp: "A^B^C", + exp: `A^B^C`, }} var ( diff --git a/parser.go b/parser.go index 8ab2f47..a210069 100644 --- a/parser.go +++ b/parser.go @@ -11,13 +11,13 @@ import ( ) const ( - macroFTP = "ftp" - macroHTTP = "http" - macroHTTPS = "https" - macroIRC = "irc" - macroImage = "image" - macroLink = "link" - macroMailto = "mailto" + macroFTP = `ftp` + macroHTTP = `http` + macroHTTPS = `https` + macroIRC = `irc` + macroImage = `image` + macroLink = `link` + macroMailto = `mailto` ) const ( @@ -93,161 +93,161 @@ const ( ) const ( - attrNameAlign = "align" - attrNameAlt = "alt" - attrNameAttribution = "attribution" - attrNameCaption = "caption" - attrNameCitation = "citation" - attrNameCols = "cols" - attrNameDiscrete = "discrete" - attrNameEnd = "end" - attrNameFloat = "float" - attrNameFrame = "frame" - attrNameGrid = "grid" - attrNameHeight = "height" - attrNameHref = "href" - attrNameIcons = "icons" - attrNameLang = "lang" - attrNameLink = "link" - attrNameOptions = "options" - attrNameOpts = "opts" - attrNamePoster = "poster" - attrNameRefText = "reftext" - attrNameRel = "rel" - attrNameRole = "role" - attrNameSource = "source" - attrNameSrc = "src" - attrNameStart = "start" - attrNameStripes = "stripes" - attrNameTarget = "target" - attrNameTheme = "theme" - attrNameTitle = "title" - attrNameVimeo = "vimeo" - attrNameWidth = "width" - attrNameYoutube = "youtube" - attrNameYoutubeLang = "hl" + attrNameAlign = `align` + attrNameAlt = `alt` + attrNameAttribution = `attribution` + attrNameCaption = `caption` + attrNameCitation = `citation` + attrNameCols = `cols` + attrNameDiscrete = `discrete` + attrNameEnd = `end` + attrNameFloat = `float` + attrNameFrame = `frame` + attrNameGrid = `grid` + attrNameHeight = `height` + attrNameHref = `href` + attrNameIcons = `icons` + attrNameLang = `lang` + attrNameLink = `link` + attrNameOptions = `options` + attrNameOpts = `opts` + attrNamePoster = `poster` + attrNameRefText = `reftext` + attrNameRel = `rel` + attrNameRole = `role` + attrNameSource = `source` + attrNameSrc = `src` + attrNameStart = `start` + attrNameStripes = `stripes` + attrNameTarget = `target` + attrNameTheme = `theme` + attrNameTitle = `title` + attrNameVimeo = `vimeo` + attrNameWidth = `width` + attrNameYoutube = `youtube` + attrNameYoutubeLang = `hl` ) const ( - attrValueAll = "all" - attrValueAuthor = "author" - attrValueBare = "bare" - attrValueBlank = "_blank" - attrValueCols = "cols" - attrValueContent = "content" - attrValueEmail = "email" - attrValueEven = "even" - attrValueFont = "font" - attrValueFooter = "footer" - attrValueHeader = "header" - attrValueHover = "hover" - attrValueImage = "image" - attrValueNoopener = "noopener" - attrValueNoHeader = "noheader" - attrValueNone = "none" - attrValueOdd = "odd" - attrValueRevDate = "revdate" - attrValueRevNumber = "revnumber" - attrValueRows = "rows" - attrValueSides = "sides" + attrValueAll = `all` + attrValueAuthor = `author` + attrValueBare = `bare` + attrValueBlank = `_blank` + attrValueCols = `cols` + attrValueContent = `content` + attrValueEmail = `email` + attrValueEven = `even` + attrValueFont = `font` + attrValueFooter = `footer` + attrValueHeader = `header` + attrValueHover = `hover` + attrValueImage = `image` + attrValueNoopener = `noopener` + attrValueNoHeader = `noheader` + attrValueNone = `none` + attrValueOdd = `odd` + attrValueRevDate = `revdate` + attrValueRevNumber = `revnumber` + attrValueRows = `rows` + attrValueSides = `sides` attrValueTitle = attrNameTitle - attrValueTopbot = "topbot" + attrValueTopbot = `topbot` ) const ( - classNameArabic = "arabic" - classNameChecklist = "checklist" - classNameFitContent = "fit-content" - classNameFrameAll = "frame-all" - classNameFrameEnds = "frame-ends" - classNameFrameNone = "frame-none" - classNameFrameSides = "frame-sides" - classNameGridAll = "grid-all" - classNameGridCols = "grid-cols" - classNameGridNone = "grid-none" - classNameGridRows = "grid-rows" - classNameLoweralpha = "loweralpha" - classNameLowerroman = "lowerroman" - classNameStretch = "stretch" - classNameStripesAll = "stripes-all" - classNameStripesEven = "stripes-even" - classNameStripesHover = "stripes-hover" - classNameStripesOdd = "stripes-odd" - classNameTableblock = "tableblock" - classNameUpperalpha = "upperalpha" - classNameUpperroman = "upperroman" + classNameArabic = `arabic` + classNameChecklist = `checklist` + classNameFitContent = `fit-content` + classNameFrameAll = `frame-all` + classNameFrameEnds = `frame-ends` + classNameFrameNone = `frame-none` + classNameFrameSides = `frame-sides` + classNameGridAll = `grid-all` + classNameGridCols = `grid-cols` + classNameGridNone = `grid-none` + classNameGridRows = `grid-rows` + classNameLoweralpha = `loweralpha` + classNameLowerroman = `lowerroman` + classNameStretch = `stretch` + classNameStripesAll = `stripes-all` + classNameStripesEven = `stripes-even` + classNameStripesHover = `stripes-hover` + classNameStripesOdd = `stripes-odd` + classNameTableblock = `tableblock` + classNameUpperalpha = `upperalpha` + classNameUpperroman = `upperroman` ) // List of document metadata. const ( - MetaNameAuthor = "author" // May contain the first author full name only. - MetaNameAuthorNames = "author_names" // List of author full names, separated by comma. - MetaNameDescription = "description" - MetaNameGenerator = "generator" - MetaNameKeywords = "keywords" - - metaNameAuthorInitials = "authorinitials" - metaNameDocTitle = "doctitle" + MetaNameAuthor = `author` // May contain the first author full name only. + MetaNameAuthorNames = `author_names` // List of author full names, separated by comma. + MetaNameDescription = `description` + MetaNameGenerator = `generator` + MetaNameKeywords = `keywords` + + metaNameAuthorInitials = `authorinitials` + metaNameDocTitle = `doctitle` metaNameEmail = attrValueEmail - metaNameFirstName = "firstname" - metaNameIDPrefix = "idprefix" - metaNameIDSeparator = "idseparator" - metaNameLastName = "lastname" - metaNameMiddleName = "middlename" - metaNameNoFooter = "nofooter" - metaNameNoHeader = "noheader" - metaNameNoHeaderFooter = "no-header-footer" - metaNameNoTitle = "notitle" - metaNameRevDate = "revdate" - metaNameRevNumber = "revnumber" - metaNameRevRemark = "revremark" - metaNameSectAnchors = "sectanchors" - metaNameSectIDs = "sectids" - metaNameSectLinks = "sectlinks" - metaNameSectNumLevel = "sectnumlevels" - metaNameSectNums = "sectnums" - metaNameShowTitle = "showtitle" - metaNameTOC = "toc" - metaNameTOCLevels = "toclevels" - metaNameTOCTitle = "toc-title" - metaNameTableCaption = "table-caption" + metaNameFirstName = `firstname` + metaNameIDPrefix = `idprefix` + metaNameIDSeparator = `idseparator` + metaNameLastName = `lastname` + metaNameMiddleName = `middlename` + metaNameNoFooter = `nofooter` + metaNameNoHeader = `noheader` + metaNameNoHeaderFooter = `no-header-footer` + metaNameNoTitle = `notitle` + metaNameRevDate = `revdate` + metaNameRevNumber = `revnumber` + metaNameRevRemark = `revremark` + metaNameSectAnchors = `sectanchors` + metaNameSectIDs = `sectids` + metaNameSectLinks = `sectlinks` + metaNameSectNumLevel = `sectnumlevels` + metaNameSectNums = `sectnums` + metaNameShowTitle = `showtitle` + metaNameTOC = `toc` + metaNameTOCLevels = `toclevels` + metaNameTOCTitle = `toc-title` + metaNameTableCaption = `table-caption` metaNameTitle = attrNameTitle - metaNameTitleSeparator = "title-separator" - metaNameVersionLabel = "version-label" + metaNameTitleSeparator = `title-separator` + metaNameVersionLabel = `version-label` ) // List of possible metadata value. const ( - metaValueAuto = "auto" - metaValueMacro = "macro" - metaValuePreamble = "preamble" - metaValueLeft = "left" - metaValueRight = "right" + metaValueAuto = `auto` + metaValueMacro = `macro` + metaValuePreamble = `preamble` + metaValueLeft = `left` + metaValueRight = `right` ) const ( - optNameAutoplay = "autoplay" - optNameAutowidth = "autowidth" - optNameControls = "controls" - optNameLoop = "loop" - optNameNocontrols = "nocontrols" - optVideoFullscreen = "fs" - optVideoModest = "modest" - optVideoNofullscreen = "nofullscreen" - optVideoPlaylist = "playlist" - optVideoYoutubeModestbranding = "modestbranding" + optNameAutoplay = `autoplay` + optNameAutowidth = `autowidth` + optNameControls = `controls` + optNameLoop = `loop` + optNameNocontrols = `nocontrols` + optVideoFullscreen = `fs` + optVideoModest = `modest` + optVideoNofullscreen = `nofullscreen` + optVideoPlaylist = `playlist` + optVideoYoutubeModestbranding = `modestbranding` ) const ( - prefixInclude = "include::" + prefixInclude = `include::` ) const ( - admonitionCaution = "CAUTION" - admonitionImportant = "IMPORTANT" - admonitionNote = "NOTE" - admonitionTip = "TIP" - admonitionWarning = "WARNING" + admonitionCaution = `CAUTION` + admonitionImportant = `IMPORTANT` + admonitionNote = `NOTE` + admonitionTip = `TIP` + admonitionWarning = `WARNING` ) const ( @@ -285,77 +285,77 @@ const ( ) const ( - symbolQuoteDoubleBegin = "“" - symbolQuoteDoubleEnd = "”" - symbolQuoteSingleBegin = "‘" - symbolQuoteSingleEnd = "’" - symbolChecked = "✓" - symbolUnchecked = "❏" + symbolQuoteDoubleBegin = `“` + symbolQuoteDoubleEnd = `”` + symbolQuoteSingleBegin = `‘` + symbolQuoteSingleEnd = `’` + symbolChecked = `✓` + symbolUnchecked = `❏` ) var adocStyles map[string]int64 = map[string]int64{ - "colophon": styleSectionColophon, - "abstract": styleSectionAbstract, - "preface": styleSectionPreface, - "dedication": styleSectionDedication, + `colophon`: styleSectionColophon, + `abstract`: styleSectionAbstract, + `preface`: styleSectionPreface, + `dedication`: styleSectionDedication, attrNameDiscrete: styleSectionDiscrete, - "partintro": styleSectionPartIntroduction, - "appendix": styleSectionAppendix, - "glossary": styleSectionGlossary, - "bibliography": styleSectionBibliography, - "index": styleSectionIndex, - ".lead": styleParagraphLead, - ".normal": styleParagraphNormal, - "arabic": styleNumberingArabic, - "decimal": styleNumberingDecimal, - "loweralpha": styleNumberingLoweralpha, - "upperalpha": styleNumberingUpperalpha, - "lowerroman": styleNumberingLowerroman, - "upperroman": styleNumberingUpperroman, - "lowergreek": styleNumberingLowergreek, - "horizontal": styleDescriptionHorizontal, - "qanda": styleDescriptionQandA, + `partintro`: styleSectionPartIntroduction, + `appendix`: styleSectionAppendix, + `glossary`: styleSectionGlossary, + `bibliography`: styleSectionBibliography, + `index`: styleSectionIndex, + `.lead`: styleParagraphLead, + `.normal`: styleParagraphNormal, + `arabic`: styleNumberingArabic, + `decimal`: styleNumberingDecimal, + `loweralpha`: styleNumberingLoweralpha, + `upperalpha`: styleNumberingUpperalpha, + `lowerroman`: styleNumberingLowerroman, + `upperroman`: styleNumberingUpperroman, + `lowergreek`: styleNumberingLowergreek, + `horizontal`: styleDescriptionHorizontal, + `qanda`: styleDescriptionQandA, admonitionCaution: styleAdmonition, admonitionImportant: styleAdmonition, admonitionNote: styleAdmonition, admonitionTip: styleAdmonition, admonitionWarning: styleAdmonition, - "listing": styleBlockListing, - "quote": styleQuote, - "source": styleSource, - "verse": styleVerse, + `listing`: styleBlockListing, + `quote`: styleQuote, + `source`: styleSource, + `verse`: styleVerse, } var _attrRef map[string]string = map[string]string{ - "amp": "&", - "apos": htmlSymbolSingleQuote, // ' - "asterisk": "*", - "backslash": `\`, - "backtick": "`", - "blank": "", - "brvbar": htmlSymbolBrokenVerticalBar, // ¦ - "caret": "^", - "cpp": "C++", - "deg": htmlSymbolDegreeSign, // ° - "empty": "", - "endsb": "]", - "gt": ">", - "ldquo": htmlSymbolLeftDoubleQuote, - "lsquo": htmlSymbolLeftSingleQuote, - "lt": "<", - "nbsp": htmlSymbolNonBreakingSpace, - "plus": htmlSymbolPlus, - "quot": htmlSymbolDoubleQuote, - "rdquo": htmlSymbolRightDoubleQuote, - "rsquo": htmlSymbolRightSingleQuote, - "sp": " ", - "startsb": "[", - "tilde": "~", - "two-colons": "::", - "two-semicolons": ";;", - "vbar": "|", - "wj": htmlSymbolWordJoiner, - "zwsp": htmlSymbolZeroWidthSpace, + `amp`: `&`, + `apos`: htmlSymbolSingleQuote, // ' + `asterisk`: `*`, + `backslash`: `\`, + `backtick`: "`", + `blank`: ``, + `brvbar`: htmlSymbolBrokenVerticalBar, // ¦ + `caret`: `^`, + `cpp`: `C++`, + `deg`: htmlSymbolDegreeSign, // ° + `empty`: ``, + `endsb`: `]`, + `gt`: `>`, + `ldquo`: htmlSymbolLeftDoubleQuote, + `lsquo`: htmlSymbolLeftSingleQuote, + `lt`: `<`, + `nbsp`: htmlSymbolNonBreakingSpace, + `plus`: htmlSymbolPlus, + `quot`: htmlSymbolDoubleQuote, + `rdquo`: htmlSymbolRightDoubleQuote, + `rsquo`: htmlSymbolRightSingleQuote, + `sp`: ` `, + `startsb`: `[`, + `tilde`: `~`, + `two-colons`: `::`, + `two-semicolons`: `;;`, + `vbar`: `|`, + `wj`: htmlSymbolWordJoiner, + `zwsp`: htmlSymbolZeroWidthSpace, } func applySubstitutions(doc *Document, content []byte) []byte { @@ -500,7 +500,7 @@ func isLineDescriptionItem(line []byte) bool { x int ) - _, x = indexUnescape(line, []byte(":: ")) + _, x = indexUnescape(line, []byte(`:: `)) if x > 0 { return true } @@ -508,7 +508,7 @@ func isLineDescriptionItem(line []byte) bool { if x > 0 { return true } - _, x = indexUnescape(line, []byte("::")) + _, x = indexUnescape(line, []byte(`::`)) return x > 0 } @@ -578,7 +578,7 @@ func parseAttribute(line []byte, strict bool) (key, value string, ok bool) { ) if !(ascii.IsAlnum(line[1]) || line[1] == '_') { - return "", "", false + return ``, ``, false } sb.WriteByte(line[1]) @@ -593,11 +593,11 @@ func parseAttribute(line []byte, strict bool) (key, value string, ok bool) { continue } if strict { - return "", "", false + return ``, ``, false } } if x == len(line) { - return "", "", false + return ``, ``, false } valb = bytes.TrimSpace(line[x+1:]) @@ -634,8 +634,8 @@ func parseAttrRef(doc *Document, content []byte, x int) (newContent []byte, ok b // Add prefix "mailto:" if the ref name start with email, so // it can be parsed by caller as macro link. - if name == "email" || strings.HasPrefix(name, "email_") { - attrValue = "mailto:" + attrValue + "[" + attrValue + "]" + if name == `email` || strings.HasPrefix(name, `email_`) { + attrValue = `mailto:` + attrValue + `[` + attrValue + `]` } } @@ -650,7 +650,7 @@ func parseAttrRef(doc *Document, content []byte, x int) (newContent []byte, ok b // It will return empty id and label if ID is not valid. func parseIDLabel(s []byte) (id, label []byte) { var ( - idLabel [][]byte = bytes.Split(s, []byte(",")) + idLabel [][]byte = bytes.Split(s, []byte(`,`)) ) id = idLabel[0] @@ -699,68 +699,68 @@ func whatKindOfLine(line []byte) (kind int, spaces, got []byte) { if len(line) == 0 { return lineKindEmpty, nil, line } - if bytes.HasPrefix(line, []byte("////")) { + if bytes.HasPrefix(line, []byte(`////`)) { // Check for comment block first, since we use HasPrefix to // check for single line comment. return lineKindBlockComment, spaces, line } - if bytes.HasPrefix(line, []byte("//")) { + if bytes.HasPrefix(line, []byte(`//`)) { // Use HasPrefix to allow single line comment without space, // for example "//comment". return lineKindComment, spaces, line } - if bytes.Equal(line, []byte("'''")) || - bytes.Equal(line, []byte("---")) || - bytes.Equal(line, []byte("- - -")) || - bytes.Equal(line, []byte("***")) || - bytes.Equal(line, []byte("* * *")) { + if bytes.Equal(line, []byte(`'''`)) || + bytes.Equal(line, []byte(`---`)) || + bytes.Equal(line, []byte(`- - -`)) || + bytes.Equal(line, []byte(`***`)) || + bytes.Equal(line, []byte(`* * *`)) { return lineKindHorizontalRule, spaces, line } - if bytes.Equal(line, []byte("<<<")) { + if bytes.Equal(line, []byte(`<<<`)) { return lineKindPageBreak, spaces, line } - if bytes.Equal(line, []byte("--")) { + if bytes.Equal(line, []byte(`--`)) { return elKindBlockOpen, spaces, line } - if bytes.Equal(line, []byte("____")) { + if bytes.Equal(line, []byte(`____`)) { return elKindBlockExcerpts, spaces, line } - if bytes.Equal(line, []byte("....")) { + if bytes.Equal(line, []byte(`....`)) { return elKindBlockLiteral, nil, line } - if bytes.Equal(line, []byte("++++")) { + if bytes.Equal(line, []byte(`++++`)) { return elKindBlockPassthrough, spaces, line } - if bytes.Equal(line, []byte("****")) { + if bytes.Equal(line, []byte(`****`)) { return elKindBlockSidebar, nil, line } - if bytes.Equal(line, []byte("====")) { + if bytes.Equal(line, []byte(`====`)) { return elKindBlockExample, spaces, line } - if bytes.HasPrefix(line, []byte("|===")) { + if bytes.HasPrefix(line, []byte(`|===`)) { return elKindTable, nil, line } - if bytes.Equal(line, []byte("[listing]")) { + if bytes.Equal(line, []byte(`[listing]`)) { return elKindBlockListingNamed, nil, line } - if bytes.Equal(line, []byte("[literal]")) { + if bytes.Equal(line, []byte(`[literal]`)) { return elKindBlockLiteralNamed, nil, line } - if bytes.Equal(line, []byte("toc::[]")) { + if bytes.Equal(line, []byte(`toc::[]`)) { return elKindMacroTOC, spaces, line } - if bytes.HasPrefix(line, []byte("image::")) { + if bytes.HasPrefix(line, []byte(`image::`)) { return elKindBlockImage, spaces, line } - if bytes.HasPrefix(line, []byte("include::")) { + if bytes.HasPrefix(line, []byte(`include::`)) { return lineKindInclude, nil, line } - if bytes.HasPrefix(line, []byte("video::")) { + if bytes.HasPrefix(line, []byte(`video::`)) { return elKindBlockVideo, nil, line } - if bytes.HasPrefix(line, []byte("audio::")) { + if bytes.HasPrefix(line, []byte(`audio::`)) { return elKindBlockAudio, nil, line } if isAdmonition(line) { @@ -828,15 +828,15 @@ func whatKindOfLine(line []byte) (kind int, spaces, got []byte) { subs [][]byte = bytes.Fields(line) ) - if bytes.Equal(subs[0], []byte("==")) { + if bytes.Equal(subs[0], []byte(`==`)) { kind = elKindSectionL1 - } else if bytes.Equal(subs[0], []byte("===")) { + } else if bytes.Equal(subs[0], []byte(`===`)) { kind = elKindSectionL2 - } else if bytes.Equal(subs[0], []byte("====")) { + } else if bytes.Equal(subs[0], []byte(`====`)) { kind = elKindSectionL3 - } else if bytes.Equal(subs[0], []byte("=====")) { + } else if bytes.Equal(subs[0], []byte(`=====`)) { kind = elKindSectionL4 - } else if bytes.Equal(subs[0], []byte("======")) { + } else if bytes.Equal(subs[0], []byte(`======`)) { kind = elKindSectionL5 } } else if line[0] == '.' { @@ -873,9 +873,9 @@ func whatKindOfLine(line []byte) (kind int, spaces, got []byte) { return kind, spaces, line } } - } else if bytes.Equal(line, []byte("+")) { + } else if bytes.Equal(line, []byte(`+`)) { kind = lineKindListContinue - } else if bytes.Equal(line, []byte("----")) { + } else if bytes.Equal(line, []byte(`----`)) { kind = elKindBlockListing } else if isLineDescriptionItem(line) { kind = elKindListDescriptionItem diff --git a/parser_test.go b/parser_test.go index d443530..ace7581 100644 --- a/parser_test.go +++ b/parser_test.go @@ -94,10 +94,10 @@ func TestIsValidID(t *testing.T) { } var cases = []testCase{{ - id: "a", + id: `a`, exp: true, }, { - id: "1", + id: `1`, }} var ( diff --git a/revision_test.go b/revision_test.go index 3e08e36..a5e5a23 100644 --- a/revision_test.go +++ b/revision_test.go @@ -16,44 +16,44 @@ func TestParseRevision(t *testing.T) { } var cases = []testCase{{ - raw: "v1", + raw: `v1`, exp: Revision{ - Number: "1", + Number: `1`, }, }, { - raw: "15 Nov, 2020", + raw: `15 Nov, 2020`, exp: Revision{ - Date: "15 Nov, 2020", + Date: `15 Nov, 2020`, }, }, { - raw: ":remark", + raw: `:remark`, exp: Revision{ - Remark: "remark", + Remark: `remark`, }, }, { - raw: "v1, 15 Nov, 2020", + raw: `v1, 15 Nov, 2020`, exp: Revision{ - Number: "1", - Date: "15 Nov, 2020", + Number: `1`, + Date: `15 Nov, 2020`, }, }, { - raw: "v1: remark", + raw: `v1: remark`, exp: Revision{ - Number: "1", - Remark: "remark", + Number: `1`, + Remark: `remark`, }, }, { - raw: "15 Nov, 2020: remark", + raw: `15 Nov, 2020: remark`, exp: Revision{ - Date: "15 Nov, 2020", - Remark: "remark", + Date: `15 Nov, 2020`, + Remark: `remark`, }, }, { - raw: "v1, 15 Nov: remark", + raw: `v1, 15 Nov: remark`, exp: Revision{ - Number: "1", - Date: "15 Nov", - Remark: "remark", + Number: `1`, + Date: `15 Nov`, + Remark: `remark`, }, }} @@ -64,6 +64,6 @@ func TestParseRevision(t *testing.T) { for _, c = range cases { got = parseRevision(c.raw) - test.Assert(t, "Revision", c.exp, got) + test.Assert(t, `Revision`, c.exp, got) } } diff --git a/section_counters.go b/section_counters.go index 7ca685b..8dff0e0 100644 --- a/section_counters.go +++ b/section_counters.go @@ -47,7 +47,7 @@ func (sec *sectionCounters) String() string { if sec.nums[x] == 0 { break } - fmt.Fprintf(&sb, "%d.", sec.nums[x]) + fmt.Fprintf(&sb, `%d.`, sec.nums[x]) } sb.WriteByte(' ') return sb.String() diff --git a/section_counters_test.go b/section_counters_test.go index 284b3d0..7018522 100644 --- a/section_counters_test.go +++ b/section_counters_test.go @@ -22,42 +22,42 @@ func TestSectionCounters(t *testing.T) { nums: [6]byte{0, 1, 0, 0, 0, 0}, curr: 1, }, - expString: "1. ", + expString: `1. `, }, { level: 1, exp: §ionCounters{ nums: [6]byte{0, 2, 0, 0, 0, 0}, curr: 1, }, - expString: "2. ", + expString: `2. `, }, { level: 2, exp: §ionCounters{ nums: [6]byte{0, 2, 1, 0, 0, 0}, curr: 2, }, - expString: "2.1. ", + expString: `2.1. `, }, { level: 3, exp: §ionCounters{ nums: [6]byte{0, 2, 1, 1, 0, 0}, curr: 3, }, - expString: "2.1.1. ", + expString: `2.1.1. `, }, { level: 2, exp: §ionCounters{ nums: [6]byte{0, 2, 2, 0, 0, 0}, curr: 2, }, - expString: "2.2. ", + expString: `2.2. `, }, { level: 1, exp: §ionCounters{ nums: [6]byte{0, 3, 0, 0, 0, 0}, curr: 1, }, - expString: "3. ", + expString: `3. `, }} var ( @@ -71,7 +71,7 @@ func TestSectionCounters(t *testing.T) { for _, c = range cases { got = sec.set(c.level) gotString = got.String() - test.Assert(t, "set", c.exp, got) - test.Assert(t, "String", c.expString, gotString) + test.Assert(t, `set`, c.exp, got) + test.Assert(t, `String`, c.expString, gotString) } } diff --git a/table_parser_test.go b/table_parser_test.go index dd71f2e..0c37654 100644 --- a/table_parser_test.go +++ b/table_parser_test.go @@ -17,51 +17,51 @@ func TestTableParser_new(t *testing.T) { } var cases = []testCase{{ - desc: "empty content", + desc: `empty content`, content: ``, exp: nil, }, { - desc: "first cell without |", - content: "A1|B1", + desc: `first cell without |`, + content: `A1|B1`, exp: []*tableCell{{ - content: []byte("A1"), + content: []byte(`A1`), }, { - content: []byte("B1"), + content: []byte(`B1`), }}, }, { - desc: "first cell without |", + desc: `first cell without |`, content: "A1\nb|B1", exp: []*tableCell{{ content: []byte("A1\nb"), }, { - content: []byte("B1"), + content: []byte(`B1`), }}, }, { - desc: "single row", + desc: `single row`, content: `|A1|B1`, exp: []*tableCell{{ - content: []byte("A1"), + content: []byte(`A1`), }, { - content: []byte("B1"), + content: []byte(`B1`), }}, }, { - desc: "two rows, empty header", + desc: `two rows, empty header`, content: "\n|A1", exp: []*tableCell{nil, { - content: []byte("A1"), + content: []byte(`A1`), }}, }, { - desc: "three rows, empty header", + desc: `three rows, empty header`, content: "\n|A1 |\n\nb\n\n|A2", exp: []*tableCell{nil, { - content: []byte("A1 "), + content: []byte(`A1 `), }, { content: []byte("\n\nb"), }, nil, { - content: []byte("A2"), + content: []byte(`A2`), }}, }, { - desc: "with cell formatting", + desc: `with cell formatting`, content: "3*|DUP\n^|A2\n3*x|B2\n>|C2", exp: []*tableCell{{ content: []byte("DUP\n"), @@ -76,7 +76,7 @@ func TestTableParser_new(t *testing.T) { }, { content: []byte("B2\n"), }, { - content: []byte("C2"), + content: []byte(`C2`), format: cellFormat{ alignHor: colAlignBottom, }, -- cgit v1.3