{"id":13413946,"url":"https://github.com/russross/blackfriday","last_synced_at":"2025-05-13T18:04:57.947Z","repository":{"id":565140,"uuid":"1812190","full_name":"russross/blackfriday","owner":"russross","description":"Blackfriday: a markdown processor for Go","archived":false,"fork":false,"pushed_at":"2024-01-29T03:41:57.000Z","size":1356,"stargazers_count":5546,"open_issues_count":218,"forks_count":604,"subscribers_count":92,"default_branch":"master","last_synced_at":"2025-05-06T17:13:53.033Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/russross.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-05-27T22:28:58.000Z","updated_at":"2025-05-03T07:59:01.000Z","dependencies_parsed_at":"2024-06-18T10:56:34.023Z","dependency_job_id":null,"html_url":"https://github.com/russross/blackfriday","commit_stats":{"total_commits":336,"total_committers":64,"mean_commits":5.25,"dds":0.7648809523809523,"last_synced_commit":"e96880f42b9343aea6cbfd99693adae0e5fe2b2a"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russross%2Fblackfriday","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russross%2Fblackfriday/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russross%2Fblackfriday/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russross%2Fblackfriday/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/russross","download_url":"https://codeload.github.com/russross/blackfriday/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254000824,"owners_count":21997441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:01:53.383Z","updated_at":"2025-05-13T18:04:57.920Z","avatar_url":"https://github.com/russross.png","language":"Go","readme":"Blackfriday\n[![Build Status][BuildV2SVG]][BuildV2URL]\n[![PkgGoDev][PkgGoDevV2SVG]][PkgGoDevV2URL]\n===========\n\nBlackfriday is a [Markdown][1] processor implemented in [Go][2]. It\nis paranoid about its input (so you can safely feed it user-supplied\ndata), it is fast, it supports common extensions (tables, smart\npunctuation substitutions, etc.), and it is safe for all utf-8\n(unicode) input.\n\nHTML output is currently supported, along with Smartypants\nextensions.\n\nIt started as a translation from C of [Sundown][3].\n\n\nInstallation\n------------\n\nBlackfriday is compatible with modern Go releases in module mode.\nWith Go installed:\n\n    go get github.com/russross/blackfriday\n\nwill resolve and add the package to the current development module,\nthen build and install it. Alternatively, you can achieve the same\nif you import it in a package:\n\n    import \"github.com/russross/blackfriday\"\n\nand `go get` without parameters.\n\nOld versions of Go and legacy GOPATH mode might work,\nbut no effort is made to keep them working.\n\n\nVersions\n--------\n\nCurrently maintained and recommended version of Blackfriday is `v2`. It's being\ndeveloped on its own branch: https://github.com/russross/blackfriday/tree/v2 and the\ndocumentation is available at\nhttps://pkg.go.dev/github.com/russross/blackfriday/v2.\n\nIt is `go get`-able in module mode at `github.com/russross/blackfriday/v2`.\n\nVersion 2 offers a number of improvements over v1:\n\n* Cleaned up API\n* A separate call to [`Parse`][4], which produces an abstract syntax tree for\n  the document\n* Latest bug fixes\n* Flexibility to easily add your own rendering extensions\n\nPotential drawbacks:\n\n* Our benchmarks show v2 to be slightly slower than v1. Currently in the\n  ballpark of around 15%.\n* API breakage. If you can't afford modifying your code to adhere to the new API\n  and don't care too much about the new features, v2 is probably not for you.\n* Several bug fixes are trailing behind and still need to be forward-ported to\n  v2. See issue [#348](https://github.com/russross/blackfriday/issues/348) for\n  tracking.\n\nIf you are still interested in the legacy `v1`, you can import it from\n`github.com/russross/blackfriday`. Documentation for the legacy v1 can be found\nhere: https://pkg.go.dev/github.com/russross/blackfriday.\n\n\nUsage\n-----\n\n### v1\n\nFor basic usage, it is as simple as getting your input into a byte\nslice and calling:\n\n```go\noutput := blackfriday.MarkdownBasic(input)\n```\n\nThis renders it with no extensions enabled. To get a more useful\nfeature set, use this instead:\n\n```go\noutput := blackfriday.MarkdownCommon(input)\n```\n\n### v2\n\nFor the most sensible markdown processing, it is as simple as getting your input\ninto a byte slice and calling:\n\n```go\noutput := blackfriday.Run(input)\n```\n\nYour input will be parsed and the output rendered with a set of most popular\nextensions enabled. If you want the most basic feature set, corresponding with\nthe bare Markdown specification, use:\n\n```go\noutput := blackfriday.Run(input, blackfriday.WithNoExtensions())\n```\n\n### Sanitize untrusted content\n\nBlackfriday itself does nothing to protect against malicious content. If you are\ndealing with user-supplied markdown, we recommend running Blackfriday's output\nthrough HTML sanitizer such as [Bluemonday][5].\n\nHere's an example of simple usage of Blackfriday together with Bluemonday:\n\n```go\nimport (\n    \"github.com/microcosm-cc/bluemonday\"\n    \"github.com/russross/blackfriday\"\n)\n\n// ...\nunsafe := blackfriday.Run(input)\nhtml := bluemonday.UGCPolicy().SanitizeBytes(unsafe)\n```\n\n### Custom options, v1\n\nIf you want to customize the set of options, first get a renderer\n(currently only the HTML output engine), then use it to\ncall the more general `Markdown` function. For examples, see the\nimplementations of `MarkdownBasic` and `MarkdownCommon` in\n`markdown.go`.\n\n### Custom options, v2\n\nIf you want to customize the set of options, use `blackfriday.WithExtensions`,\n`blackfriday.WithRenderer` and `blackfriday.WithRefOverride`.\n\n### `blackfriday-tool`\n\nYou can also check out `blackfriday-tool` for a more complete example\nof how to use it. Download and install it using:\n\n    go get github.com/russross/blackfriday-tool\n\nThis is a simple command-line tool that allows you to process a\nmarkdown file using a standalone program.  You can also browse the\nsource directly on github if you are just looking for some example\ncode:\n\n* \u003chttps://github.com/russross/blackfriday-tool\u003e\n\nNote that if you have not already done so, installing\n`blackfriday-tool` will be sufficient to download and install\nblackfriday in addition to the tool itself. The tool binary will be\ninstalled in `$GOPATH/bin`.  This is a statically-linked binary that\ncan be copied to wherever you need it without worrying about\ndependencies and library versions.\n\n### Sanitized anchor names\n\nBlackfriday includes an algorithm for creating sanitized anchor names\ncorresponding to a given input text. This algorithm is used to create\nanchors for headings when `EXTENSION_AUTO_HEADER_IDS` is enabled. The\nalgorithm has a specification, so that other packages can create\ncompatible anchor names and links to those anchors.\n\nThe specification is located at https://pkg.go.dev/github.com/russross/blackfriday#hdr-Sanitized_Anchor_Names.\n\n[`SanitizedAnchorName`](https://pkg.go.dev/github.com/russross/blackfriday#SanitizedAnchorName) exposes this functionality, and can be used to\ncreate compatible links to the anchor names generated by blackfriday.\nThis algorithm is also implemented in a small standalone package at\n[`github.com/shurcooL/sanitized_anchor_name`](https://pkg.go.dev/github.com/shurcooL/sanitized_anchor_name). It can be useful for clients\nthat want a small package and don't need full functionality of blackfriday.\n\n\nFeatures\n--------\n\nAll features of Sundown are supported, including:\n\n*   **Compatibility**. The Markdown v1.0.3 test suite passes with\n    the `--tidy` option.  Without `--tidy`, the differences are\n    mostly in whitespace and entity escaping, where blackfriday is\n    more consistent and cleaner.\n\n*   **Common extensions**, including table support, fenced code\n    blocks, autolinks, strikethroughs, non-strict emphasis, etc.\n\n*   **Safety**. Blackfriday is paranoid when parsing, making it safe\n    to feed untrusted user input without fear of bad things\n    happening. The test suite stress tests this and there are no\n    known inputs that make it crash.  If you find one, please let me\n    know and send me the input that does it.\n\n    NOTE: \"safety\" in this context means *runtime safety only*. In order to\n    protect yourself against JavaScript injection in untrusted content, see\n    [this example](https://github.com/russross/blackfriday#sanitize-untrusted-content).\n\n*   **Fast processing**. It is fast enough to render on-demand in\n    most web applications without having to cache the output.\n\n*   **Thread safety**. You can run multiple parsers in different\n    goroutines without ill effect. There is no dependence on global\n    shared state.\n\n*   **Minimal dependencies**. Blackfriday only depends on standard\n    library packages in Go. The source code is pretty\n    self-contained, so it is easy to add to any project, including\n    Google App Engine projects.\n\n*   **Standards compliant**. Output successfully validates using the\n    W3C validation tool for HTML 4.01 and XHTML 1.0 Transitional.\n\n\nExtensions\n----------\n\nIn addition to the standard markdown syntax, this package\nimplements the following extensions:\n\n*   **Intra-word emphasis supression**. The `_` character is\n    commonly used inside words when discussing code, so having\n    markdown interpret it as an emphasis command is usually the\n    wrong thing. Blackfriday lets you treat all emphasis markers as\n    normal characters when they occur inside a word.\n\n*   **Tables**. Tables can be created by drawing them in the input\n    using a simple syntax:\n\n    ```\n    Name    | Age\n    --------|------\n    Bob     | 27\n    Alice   | 23\n    ```\n\n*   **Fenced code blocks**. In addition to the normal 4-space\n    indentation to mark code blocks, you can explicitly mark them\n    and supply a language (to make syntax highlighting simple). Just\n    mark it like this:\n\n        ```go\n        func getTrue() bool {\n            return true\n        }\n        ```\n\n    You can use 3 or more backticks to mark the beginning of the\n    block, and the same number to mark the end of the block.\n\n    To preserve classes of fenced code blocks while using the bluemonday\n    HTML sanitizer, use the following policy:\n\n    ```go\n    p := bluemonday.UGCPolicy()\n    p.AllowAttrs(\"class\").Matching(regexp.MustCompile(\"^language-[a-zA-Z0-9]+$\")).OnElements(\"code\")\n    html := p.SanitizeBytes(unsafe)\n    ```\n\n*   **Definition lists**. A simple definition list is made of a single-line\n    term followed by a colon and the definition for that term.\n\n        Cat\n        : Fluffy animal everyone likes\n\n        Internet\n        : Vector of transmission for pictures of cats\n\n    Terms must be separated from the previous definition by a blank line.\n\n*   **Footnotes**. A marker in the text that will become a superscript number;\n    a footnote definition that will be placed in a list of footnotes at the\n    end of the document. A footnote looks like this:\n\n        This is a footnote.[^1]\n\n        [^1]: the footnote text.\n\n*   **Autolinking**. Blackfriday can find URLs that have not been\n    explicitly marked as links and turn them into links.\n\n*   **Strikethrough**. Use two tildes (`~~`) to mark text that\n    should be crossed out.\n\n*   **Hard line breaks**. With this extension enabled (it is off by\n    default in the `MarkdownBasic` and `MarkdownCommon` convenience\n    functions), newlines in the input translate into line breaks in\n    the output.\n\n*   **Smart quotes**. Smartypants-style punctuation substitution is\n    supported, turning normal double- and single-quote marks into\n    curly quotes, etc.\n\n*   **LaTeX-style dash parsing** is an additional option, where `--`\n    is translated into `\u0026ndash;`, and `---` is translated into\n    `\u0026mdash;`. This differs from most smartypants processors, which\n    turn a single hyphen into an ndash and a double hyphen into an\n    mdash.\n\n*   **Smart fractions**, where anything that looks like a fraction\n    is translated into suitable HTML (instead of just a few special\n    cases like most smartypant processors). For example, `4/5`\n    becomes `\u003csup\u003e4\u003c/sup\u003e\u0026frasl;\u003csub\u003e5\u003c/sub\u003e`, which renders as\n    \u003csup\u003e4\u003c/sup\u003e\u0026frasl;\u003csub\u003e5\u003c/sub\u003e.\n\n\nOther renderers\n---------------\n\nBlackfriday is structured to allow alternative rendering engines. Here\nare a few of note:\n\n*   [github_flavored_markdown](https://pkg.go.dev/github.com/shurcooL/github_flavored_markdown):\n    provides a GitHub Flavored Markdown renderer with fenced code block\n    highlighting, clickable heading anchor links.\n\n    It's not customizable, and its goal is to produce HTML output\n    equivalent to the [GitHub Markdown API endpoint](https://developer.github.com/v3/markdown/#render-a-markdown-document-in-raw-mode),\n    except the rendering is performed locally.\n\n*   [markdownfmt](https://github.com/shurcooL/markdownfmt): like gofmt,\n    but for markdown.\n\n*   [LaTeX output](https://gitlab.com/ambrevar/blackfriday-latex):\n    renders output as LaTeX.\n\n*   [bfchroma](https://github.com/Depado/bfchroma/): provides convenience\n    integration with the [Chroma](https://github.com/alecthomas/chroma) code\n    highlighting library. bfchroma is only compatible with v2 of Blackfriday and\n    provides a drop-in renderer ready to use with Blackfriday, as well as\n    options and means for further customization.\n\n*   [Blackfriday-Confluence](https://github.com/kentaro-m/blackfriday-confluence): provides a [Confluence Wiki Markup](https://confluence.atlassian.com/doc/confluence-wiki-markup-251003035.html) renderer.\n\n*   [Blackfriday-Slack](https://github.com/karriereat/blackfriday-slack): converts markdown to slack message style\n\n\nTODO\n----\n\n*   More unit testing\n*   Improve Unicode support. It does not understand all Unicode\n    rules (about what constitutes a letter, a punctuation symbol,\n    etc.), so it may fail to detect word boundaries correctly in\n    some instances. It is safe on all UTF-8 input.\n\n\nLicense\n-------\n\n[Blackfriday is distributed under the Simplified BSD License](LICENSE.txt)\n\n\n   [1]: https://daringfireball.net/projects/markdown/ \"Markdown\"\n   [2]: https://golang.org/ \"Go Language\"\n   [3]: https://github.com/vmg/sundown \"Sundown\"\n   [4]: https://pkg.go.dev/github.com/russross/blackfriday/v2#Parse \"Parse func\"\n   [5]: https://github.com/microcosm-cc/bluemonday \"Bluemonday\"\n\n   [BuildV2SVG]: https://travis-ci.org/russross/blackfriday.svg?branch=v2\n   [BuildV2URL]: https://travis-ci.org/russross/blackfriday\n   [PkgGoDevV2SVG]: https://pkg.go.dev/badge/github.com/russross/blackfriday/v2\n   [PkgGoDevV2URL]: https://pkg.go.dev/github.com/russross/blackfriday/v2\n","funding_links":[],"categories":["开源类库","Misc","Text Processing","Go","Markdown parser","Open source library","文本处理","Specific Formats","文本處理","Bot Building","Markdown Libraries","\u003cspan id=\"文字处理-text-processing\"\u003e文字处理 Text Processing\u003c/span\u003e","文本处理`解析和操作文本的代码库`","Template Engines"],"sub_categories":["文本处理","Markup Languages","HTTP Clients","Advanced Console UIs","Word Processing","标记语言","高級控制台界面","查询语","GO Markdown Libraries","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","Middlewares","交流","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frussross%2Fblackfriday","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frussross%2Fblackfriday","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frussross%2Fblackfriday/lists"}