From 620ae4182490ac8cfa8b1fcfd11c8f4802eb7c10 Mon Sep 17 00:00:00 2001 From: GRosenberg Date: Sun, 11 May 2014 18:27:14 -0700 Subject: [PATCH 1/8] Add support for header IDs --- main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main.go b/main.go index 60836c2..2d35dab 100644 --- a/main.go +++ b/main.go @@ -120,6 +120,7 @@ func main() { extensions |= blackfriday.EXTENSION_AUTOLINK extensions |= blackfriday.EXTENSION_STRIKETHROUGH extensions |= blackfriday.EXTENSION_SPACE_HEADERS + extensions |= blackfriday.EXTENSION_HEADER_IDS var renderer blackfriday.Renderer if latex { From ec150701f0abf1c20b66c48410f74e3a68b4f58a Mon Sep 17 00:00:00 2001 From: "tal@whatexit.org" Date: Tue, 6 Oct 2015 16:16:08 -0400 Subject: [PATCH 2/8] Add -mdtoc flag which outputs a MarkDown ToC. --- main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 60836c2..201d33a 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,7 @@ const DEFAULT_TITLE = "" func main() { // parse command-line options - var page, toc, toconly, xhtml, latex, smartypants, latexdashes, fractions bool + var page, toc, toconly, mdtoc, xhtml, latex, smartypants, latexdashes, fractions bool var css, cpuprofile string var repeat int flag.BoolVar(&page, "page", false, @@ -38,6 +38,8 @@ func main() { "Generate a table of contents (implies -latex=false)") flag.BoolVar(&toconly, "toconly", false, "Generate a table of contents only (implies -toc)") + flag.BoolVar(&mdtoc, "mdtoc", false, + "Generate a MarkDown table of contents only (implies -toc -toconly -latex=false)") flag.BoolVar(&xhtml, "xhtml", true, "Use XHTML-style tags in HTML output") flag.BoolVar(&latex, "latex", false, @@ -81,6 +83,11 @@ func main() { if toc { latex = false } + if mdtoc { + toc = true + toconly = true + latex = false + } // turn on profiling? if cpuprofile != "" { @@ -145,6 +152,9 @@ func main() { htmlFlags |= blackfriday.HTML_COMPLETE_PAGE title = getTitle(input) } + if mdtoc { + htmlFlags |= blackfriday.HTML_TOC_MD + } if toconly { htmlFlags |= blackfriday.HTML_OMIT_CONTENTS } From 852236c8fe3951a1f5a2cbf735069719e8c275b0 Mon Sep 17 00:00:00 2001 From: "tal@whatexit.org" Date: Mon, 12 Oct 2015 02:49:17 +0000 Subject: [PATCH 3/8] New flag: -anchorstyle=(legacy|github|gitlab) --- main.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 201d33a..2c64f2b 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,8 @@ import ( "os" "runtime/pprof" "strings" + + "github.com/shurcooL/sanitized_anchor_name" ) const DEFAULT_TITLE = "" @@ -30,7 +32,7 @@ const DEFAULT_TITLE = "" func main() { // parse command-line options var page, toc, toconly, mdtoc, xhtml, latex, smartypants, latexdashes, fractions bool - var css, cpuprofile string + var css, cpuprofile, anchorstyle string var repeat int flag.BoolVar(&page, "page", false, "Generate a standalone HTML page (implies -latex=false)") @@ -40,6 +42,8 @@ func main() { "Generate a table of contents only (implies -toc)") flag.BoolVar(&mdtoc, "mdtoc", false, "Generate a MarkDown table of contents only (implies -toc -toconly -latex=false)") + flag.StringVar(&anchorstyle, "anchorstyle", "gitlab", + "When used with -mdtoc selects compatibility: gitlab, github, legacy") flag.BoolVar(&xhtml, "xhtml", true, "Use XHTML-style tags in HTML output") flag.BoolVar(&latex, "latex", false, @@ -161,7 +165,24 @@ func main() { if toc { htmlFlags |= blackfriday.HTML_TOC } - renderer = blackfriday.HtmlRenderer(htmlFlags, title, css) + + // Determine which anchor generator to use. + sanitizeMap := map[string]func(string) string{ + "legacy": sanitized_anchor_name.Create, + "github": sanitized_anchor_name.CreateGitHub, + "gitlab": sanitized_anchor_name.CreateGitLab, + // undocumented aliases: + "hub": sanitized_anchor_name.CreateGitHub, + "lab": sanitized_anchor_name.CreateGitLab, + } + sanitize := sanitizeMap[anchorstyle] + if sanitize == nil { + fmt.Fprintln(os.Stderr, "Not a valid -anchorstyle: %v", anchorstyle) + os.Exit(-1) + } + + renderer = blackfriday.HtmlRenderer(htmlFlags, title, css, sanitize) + //renderer = blackfriday.HtmlRenderer(htmlFlags, title, css, nil) } // parse and render From 6d8747cef465ad660493d476af52b998cd73d25e Mon Sep 17 00:00:00 2001 From: "tal@whatexit.org" Date: Mon, 12 Oct 2015 03:11:56 +0000 Subject: [PATCH 4/8] Fix "go vet" warning. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 2c64f2b..7ab8ba5 100644 --- a/main.go +++ b/main.go @@ -177,7 +177,7 @@ func main() { } sanitize := sanitizeMap[anchorstyle] if sanitize == nil { - fmt.Fprintln(os.Stderr, "Not a valid -anchorstyle: %v", anchorstyle) + fmt.Fprintln(os.Stderr, "Not a valid -anchorstyle:", anchorstyle) os.Exit(-1) } From cd77bbd804f41627ca2063053d850b5ed2e4430a Mon Sep 17 00:00:00 2001 From: "tal@whatexit.org" Date: Mon, 12 Oct 2015 15:51:48 +0000 Subject: [PATCH 5/8] Reduce duplication of effort. --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 7ab8ba5..7e9d891 100644 --- a/main.go +++ b/main.go @@ -181,8 +181,8 @@ func main() { os.Exit(-1) } - renderer = blackfriday.HtmlRenderer(htmlFlags, title, css, sanitize) - //renderer = blackfriday.HtmlRenderer(htmlFlags, title, css, nil) + renderer = blackfriday.HtmlRendererWithParameters(htmlFlags, title, css, + blackfriday.HtmlRendererParameters{SanitizedAnchorNameOverride: sanitize}) } // parse and render From f762fc59aa404589fd70f8fa27628ccab0e3fbd0 Mon Sep 17 00:00:00 2001 From: "tal@whatexit.org" Date: Fri, 22 Jan 2016 00:16:22 -0500 Subject: [PATCH 6/8] Use github.com/TomOnTime/markdownutils --- main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 7e9d891..1f68a32 100644 --- a/main.go +++ b/main.go @@ -18,12 +18,13 @@ package main import ( "flag" "fmt" - "github.com/russross/blackfriday" "io/ioutil" "os" "runtime/pprof" "strings" + "github.com/TomOnTime/markdownutils" + "github.com/russross/blackfriday" "github.com/shurcooL/sanitized_anchor_name" ) @@ -169,11 +170,11 @@ func main() { // Determine which anchor generator to use. sanitizeMap := map[string]func(string) string{ "legacy": sanitized_anchor_name.Create, - "github": sanitized_anchor_name.CreateGitHub, - "gitlab": sanitized_anchor_name.CreateGitLab, + "github": markdownutils.CreateGitHubAnchor, + "gitlab": markdownutils.CreateGitLabAnchor, // undocumented aliases: - "hub": sanitized_anchor_name.CreateGitHub, - "lab": sanitized_anchor_name.CreateGitLab, + "hub": markdownutils.CreateGitHubAnchor, + "lab": markdownutils.CreateGitLabAnchor, } sanitize := sanitizeMap[anchorstyle] if sanitize == nil { From 53248f7ccf6876efa5be03a12be7768ff85e6d39 Mon Sep 17 00:00:00 2001 From: "tal@whatexit.org" Date: Fri, 22 Jan 2016 13:49:49 -0500 Subject: [PATCH 7/8] s/MarkDown/Markdown/g --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 1f68a32..364c593 100644 --- a/main.go +++ b/main.go @@ -42,7 +42,7 @@ func main() { flag.BoolVar(&toconly, "toconly", false, "Generate a table of contents only (implies -toc)") flag.BoolVar(&mdtoc, "mdtoc", false, - "Generate a MarkDown table of contents only (implies -toc -toconly -latex=false)") + "Generate a Markdown table of contents only (implies -toc -toconly -latex=false)") flag.StringVar(&anchorstyle, "anchorstyle", "gitlab", "When used with -mdtoc selects compatibility: gitlab, github, legacy") flag.BoolVar(&xhtml, "xhtml", true, From 81a8e4f28e689f35e8fd41a5433c42be0be13acb Mon Sep 17 00:00:00 2001 From: GRosenberg Date: Thu, 1 Dec 2016 14:19:38 -0800 Subject: [PATCH 8/8] Rollup of PRs from forks. --- README.md | 5 +++-- main.go | 15 +++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8a98d9d..2aefa38 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Here is the help message for the tool: Blackfriday Markdown Processor v1.1 Available at http://github.com/russross/blackfriday - Copyright © 2011 Russ Ross + Copyright © 2011-2016 Russ Ross and contributors. Distributed under the Simplified BSD License See website for details @@ -25,6 +25,7 @@ Here is the help message for the tool: Options: -cpuprofile="": Write cpu profile to a file -css="": Link to a CSS stylesheet (implies -page) + -embed=false: Embed CSS stylesheet instead of linking (requires -css) -fractions=true: Use improved fraction rules for smartypants -latex=false: Generate LaTeX output instead of HTML -latexdashes=true: Use LaTeX-style dash rules for smartypants @@ -41,7 +42,7 @@ License Blackfriday is distributed under the Simplified BSD License: -> Copyright © 2011 Russ Ross. All rights reserved. +> Copyright © 2011-2016 Russ Ross and contributors. All rights reserved. > > Redistribution and use in source and binary forms, with or without modification, are > permitted provided that the following conditions are met: diff --git a/main.go b/main.go index 193116e..e77e2f4 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,7 @@ // Blackfriday Markdown Processor // Available at http://github.com/russross/blackfriday // -// Copyright © 2011 Russ Ross . +// Copyright © 2011-2016 Russ Ross and contributors. // Distributed under the Simplified BSD License. // See README.md for details. // @@ -32,7 +32,7 @@ const DEFAULT_TITLE = "" func main() { // parse command-line options - var page, toc, toconly, mdtoc, xhtml, latex, smartypants, latexdashes, fractions bool + var page, toc, toconly, mdtoc, xhtml, latex, smartypants, latexdashes, fractions, embed bool var css, cpuprofile, anchorstyle string var repeat int flag.BoolVar(&page, "page", false, @@ -57,6 +57,8 @@ func main() { "Use improved fraction rules for smartypants") flag.StringVar(&css, "css", "", "Link to a CSS stylesheet (implies -page)") + flag.BoolVar(&css, "embed", true, + "Embed CSS stylesheet instead of linking (requires -css)") flag.StringVar(&cpuprofile, "cpuprofile", "", "Write cpu profile to a file") flag.IntVar(&repeat, "repeat", 1, @@ -64,7 +66,7 @@ func main() { flag.Usage = func() { fmt.Fprintf(os.Stderr, "Blackfriday Markdown Processor v"+blackfriday.VERSION+ "\nAvailable at http://github.com/russross/blackfriday\n\n"+ - "Copyright © 2011 Russ Ross \n"+ + "Copyright © 2011-2015 Russ Ross and contributors\n"+ "Distributed under the Simplified BSD License\n"+ "See website for details\n\n"+ "Usage:\n"+ @@ -133,6 +135,7 @@ func main() { extensions |= blackfriday.EXTENSION_STRIKETHROUGH extensions |= blackfriday.EXTENSION_SPACE_HEADERS extensions |= blackfriday.EXTENSION_HEADER_IDS + extensions |= blackfriday.EXTENSION_FOOTNOTES var renderer blackfriday.Renderer if latex { @@ -167,15 +170,15 @@ func main() { if toc { htmlFlags |= blackfriday.HTML_TOC } + if embed { + htmlFlags |= blackfriday.HTML_EMBED_CSS + } // Determine which anchor generator to use. sanitizeMap := map[string]func(string) string{ "legacy": sanitized_anchor_name.Create, "github": markdownutils.CreateGitHubAnchor, "gitlab": markdownutils.CreateGitLabAnchor, - // undocumented aliases: - "hub": markdownutils.CreateGitHubAnchor, - "lab": markdownutils.CreateGitLabAnchor, } sanitize := sanitizeMap[anchorstyle] if sanitize == nil {