Example #1
0
// mmark
func GetMmarkHtmlRenderer(defaultFlags int, ctx *RenderingContext) mmark.Renderer {
	renderParameters := mmark.HtmlRendererParameters{
		FootnoteAnchorPrefix:       viper.GetString("FootnoteAnchorPrefix"),
		FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
	}

	b := len(ctx.DocumentID) != 0

	if b && !ctx.getConfig().PlainIDAnchors {
		renderParameters.FootnoteAnchorPrefix = ctx.DocumentID + ":" + renderParameters.FootnoteAnchorPrefix
		// renderParameters.HeaderIDSuffix = ":" + ctx.DocumentId
	}

	htmlFlags := defaultFlags
	htmlFlags |= mmark.HTML_FOOTNOTE_RETURN_LINKS

	return mmark.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters)
}
Example #2
0
func TestMarkdownLinks(t *testing.T) {
	file := "test/index.md"
	data.AllFiles = make(map[string]*data.FileDetails)
	data.AddFile(file, file)

	htmlFlags := 0
	renderParameters := mmark.HtmlRendererParameters{}
	renderer := &TestRenderer{
		LinkFrom: file,
		//Html:     mmark.HtmlRenderer(htmlFlags, "", "").(*mmark.Html),
		Renderer: mmark.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters),
	}
	out := bytes.NewBuffer(make([]byte, 1024))

	tests := map[string]string{
		"../first.md":            "first.md",
		"second.md":              "test/second.md",
		"./second.md":            "test/second.md",
		"banana/second.md":       "test/banana/second.md",
		"/test/banana/second.md": "test/banana/second.md",
		"twice.md":               "test/twice.md",
		"banana/twice.md":        "test/banana/twice.md",
	}

	for _, path := range tests {
		data.AddFile(path, path)
	}
	for link, _ := range tests {
		renderer.Link(out, []byte(link), []byte("title"), []byte("content"))
	}

	for link, details := range data.AllLinks {
		data.AllLinks[link].Response = testUrl(link, "", true)
		//fmt.Printf("\t\t(%d) %d links to %s\n", data.AllLinks[link].Response, details.Count, link)
		fmt.Printf("%s links to %s\n", details.ActualLink[0], link)
		if _, ok := data.AllFiles[link]; !ok {
			t.Errorf("ERROR(%d): not found %s links to %s\n", details.Response, details.ActualLink[0], link)
		}
		if tests[details.ActualLink[0]] != link {
			t.Errorf("ERROR(%d): %s links to %s, should link to %s\n", details.Response, details.ActualLink[0], link, tests[details.ActualLink[0]])
		}
	}
}
Example #3
0
func CheckMarkdownLinks(reader *linereader.LineReader, file string) (err error) {
	// mmark.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters)
	htmlFlags := 0
	htmlFlags |= mmark.HTML_FOOTNOTE_RETURN_LINKS

	renderParameters := mmark.HtmlRendererParameters{
	//		FootnoteAnchorPrefix:       viper.GetString("FootnoteAnchorPrefix"),
	//		FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
	}

	renderer := &TestRenderer{
		LinkFrom: file,
		Renderer: mmark.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters),
	}

	extensions := 0 |
		//mmark.EXTENSION_NO_INTRA_EMPHASIS |
		mmark.EXTENSION_TABLES | mmark.EXTENSION_FENCED_CODE |
		mmark.EXTENSION_AUTOLINK |
		//mmark.EXTENSION_STRIKETHROUGH |
		mmark.EXTENSION_SPACE_HEADERS | mmark.EXTENSION_FOOTNOTES |
		mmark.EXTENSION_HEADER_IDS | mmark.EXTENSION_AUTO_HEADER_IDS //|
	//	mmark.EXTENSION_DEFINITION_LISTS

	//var output []byte
	buf := make([]byte, 1024*1024)
	length, err := reader.Read(buf)
	if length == 0 || err != nil {
		return err
	}
	data.VerboseLog("RUNNING Markdown on %s length(%d) - not counting frontmater\n", file, length)
	_ = mmark.Parse(buf, renderer, extensions)
	data.VerboseLog("FINISHED Markdown on %s\n", file)

	return nil
}