Skip to content
This repository has been archived by the owner on Nov 10, 2020. It is now read-only.

Commit

Permalink
Fix tests and make notes work
Browse files Browse the repository at this point in the history
Notes are implement by using a special header.
  • Loading branch information
miekg committed Dec 8, 2015
1 parent ba539f2 commit af83dee
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 10 deletions.
8 changes: 4 additions & 4 deletions block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1425,8 +1425,8 @@ func TestAbstractNoteAsideXML(t *testing.T) {
".# Abstract\nbegin of abstract\n\nthis is an abstract\n",
"\n<abstract>\n<t>\nbegin of abstract\n</t>\n<t>\nthis is an abstract\n</t>\n</abstract>\n\n",

"N> begin of note\nN> this is a note\n",
"<note>\n<t>\nbegin of note\nthis is a note\n</t>\n</note>\n",
".# A note\nthis is the content\n",
"\n<note>\n<name>A note</name>\n<t>\nthis is the content\n</t>\n",

"A> begin of aside\nA> this is an aside\n",
"<aside>\n<t>\nbegin of aside\nthis is an aside\n</t>\n</aside>\n",
Expand Down Expand Up @@ -1502,15 +1502,15 @@ func TestInlineAttrXML(t *testing.T) {
"<artwork>\n{style=\"format REQ(%c)\" start=\"4\"}\n</artwork>\n<ol>\n<li>Term1</li>\n<li>Term2</li>\n</ol>\n",

"{.green #ref1}\n# hallo\n\n{.yellow}\n# hallo {#ref2}\n\n{.blue #ref3}\n# hallo {#ref4}\n",
"\n<section anchor=\"ref1\" class=\"green\"><name>hallo</name>\n</section>\n\n<section anchor=\"ref2\" class=\"yellow\"><name>hallo</name>\n</section>\n\n<section anchor=\"ref3\" class=\"blue\"><name>hallo</name>\n</section>\n",
"\n<section anchor=\"ref1\" class=\"green\">\n<name>hallo</name>\n</section>\n\n<section anchor=\"ref2\" class=\"yellow\">\n<name>hallo</name>\n</section>\n\n<section anchor=\"ref3\" class=\"blue\">\n<name>hallo</name>\n</section>\n",
}
doTestsBlockXML(t, tests, 0)
}

func TestCloseHeaderXML(t *testing.T) {
var tests = []string{
"# Header1\n",
"\n<section anchor=\"header1\"><name>Header1</name>\n</section>\n",
"\n<section anchor=\"header1\">\n<name>Header1</name>\n</section>\n",
}
doTestsBlockXML(t, tests, 0)
}
Expand Down
4 changes: 2 additions & 2 deletions doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var extensions = EXTENSION_TABLES | EXTENSION_FENCED_CODE | EXTENSION_AUTOLINK |

func TestCarriageReturn(t *testing.T) {
var tests = []string{".# Abstract\n\rThis document\n\r# More\n\rand more\n\r{#fig-a}\n\r```\n\rfigure\n\r```\n\rFigure: Traditional Media Server\n\r\n\r{#fig-b}\n\r```\n\rfigure\n\r```\n\rFigure: Endpoint\n\r",
"\n<abstract>\n<t>\nThis document\n</t>\n</abstract>\n\n\n<section anchor=\"more\"><name>More</name>\n<t>\nand more\n</t>\n<artwork anchor=\"fig-a\">\n\nfigure\n\n</artwork>\n<t>\nFigure: Traditional Media Server\n</t>\n<artwork anchor=\"fig-b\">\n\nfigure\n\n</artwork>\n<t>\nFigure: Endpoint\n</t>\n</section>\n",
"\n<abstract>\n<t>\nThis document\n</t>\n</abstract>\n\n\n<section anchor=\"more\">\n<name>More</name>\n<t>\nand more\n</t>\n<artwork anchor=\"fig-a\">\n\nfigure\n\n</artwork>\n<t>\nFigure: Traditional Media Server\n</t>\n<artwork anchor=\"fig-b\">\n\nfigure\n\n</artwork>\n<t>\nFigure: Endpoint\n</t>\n</section>\n",
}
doTestsBlockXML(t, tests, extensions)
}
Expand All @@ -17,7 +17,7 @@ func TestFigureCaption(t *testing.T) {
var tests = []string{
// This checks the *single* newline after the Figure: caption.
".# Abstract\nThis document\n# More\nand more\n{#fig-a}\n```\nfigure\n```\nFigure: Traditional Media Server\n\n{#fig-b}\n```\nfigure\n```\n",
"\n<abstract>\n<t>\nThis document\n</t>\n</abstract>\n\n\n<section anchor=\"more\"><name>More</name>\n<t>\nand more\n\n</t>\n<figure anchor=\"fig-a\">\n<name>Traditional Media Server\n</name>\n<artwork>\nfigure\n</artwork>\n</figure>\n<artwork anchor=\"fig-b\">\nfigure\n</artwork>\n</section>\n",
"\n<abstract>\n<t>\nThis document\n</t>\n</abstract>\n\n\n<section anchor=\"more\">\n<name>More</name>\n<t>\nand more\n\n</t>\n<figure anchor=\"fig-a\">\n<name>Traditional Media Server\n</name>\n<artwork>\nfigure\n</artwork>\n</figure>\n<artwork anchor=\"fig-b\">\nfigure\n</artwork>\n</section>\n",
}
doTestsBlockXML(t, tests, extensions)
}
9 changes: 8 additions & 1 deletion html.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,14 @@ func (options *html) Part(out *bytes.Buffer, text func() bool, id string) {
}

func (options *html) Note(out *bytes.Buffer, text func() bool, id string) {
// TODO
options.inlineAttr() //reset the IAL
if id != "" {
out.WriteString(fmt.Sprintf("<h1 class=\"note\" id=\"%s\">", id))
} else {
out.WriteString(fmt.Sprintf("<h1 class=\"note\""))
}
text()
out.WriteString(fmt.Sprintf("</h1>\n"))
}

func (options *html) SpecialHeader(out *bytes.Buffer, what []byte, text func() bool, id string) {
Expand Down
1 change: 1 addition & 0 deletions markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const (
_DOC_MAIN_MATTER
_DOC_BACK_MATTER
_ABSTRACT // Special headers, keep track if there are open
_NOTE // Special Note headers, keep track if there are open
_PREFACE
_COLOPHON
)
Expand Down
21 changes: 20 additions & 1 deletion xml2rfcv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,24 @@ func (options *xml2) Part(out *bytes.Buffer, text func() bool, id string) {
}

func (options *xml2) Note(out *bytes.Buffer, text func() bool, id string) {
// TODO
level := 1
if level <= options.sectionLevel {
// close previous ones
for i := options.sectionLevel - level + 1; i > 0; i-- {
out.WriteString("</section>\n")
}
}

ial := options.inlineAttr()


out.WriteString("\n<note" + ial.String())
out.WriteString(" title=\"")
text()
out.WriteString("\">\n")
options.sectionLevel = 0
options.specialSection = _NOTE
return
}

func (options *xml2) SpecialHeader(out *bytes.Buffer, what []byte, text func() bool, id string) {
Expand Down Expand Up @@ -247,6 +264,8 @@ func (options *xml2) Header(out *bytes.Buffer, text func() bool, level int, id s
switch options.specialSection {
case _ABSTRACT:
out.WriteString("</abstract>\n\n")
case _NOTE:
out.WriteString("</note>\n\n")
}

if level > options.sectionLevel+1 {
Expand Down
20 changes: 18 additions & 2 deletions xml2rfcv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,23 @@ func (options *xml) Part(out *bytes.Buffer, text func() bool, id string) {
}

func (options *xml) Note(out *bytes.Buffer, text func() bool, id string) {
// TODO
level := 1
if level <= options.sectionLevel {
// close previous ones
for i := options.sectionLevel - level + 1; i > 0; i-- {
out.WriteString("</section>\n")
}
}

ial := options.inlineAttr()

out.WriteString("\n<note" + ial.String() + ">\n")
out.WriteString("<name>")
text()
out.WriteString("</name>\n")
options.sectionLevel = 0
options.specialSection = _NOTE
return
}

func (options *xml) SpecialHeader(out *bytes.Buffer, what []byte, text func() bool, id string) {
Expand Down Expand Up @@ -252,7 +268,7 @@ func (options *xml) Header(out *bytes.Buffer, text func() bool, level int, id st
ial.GetOrDefaultId(id)

// new section
out.WriteString("\n<section" + ial.String() + ">")
out.WriteString("\n<section" + ial.String() + ">\n")
out.WriteString("<name>")
text()
out.WriteString("</name>\n")
Expand Down

0 comments on commit af83dee

Please sign in to comment.