• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

increments/qiita-markdown: Qiita-specified markdown processor.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

increments/qiita-markdown

开源软件地址(OpenSource Url):

https://github.com/increments/qiita-markdown

开源编程语言(OpenSource Language):

Ruby 100.0%

开源软件介绍(OpenSource Introduction):

Qiita::Markdown

Gem Version Build Status Code Climate Test Coverage

Qiita-specified markdown processor.

  • Markdown conversion
  • Sanitization
  • Code and language detection
  • Task list
  • ToC
  • Emoji
  • Syntax highlighting
  • Mention
  • Footnotes

Basic Usage

Qiita::Markdown::Processor provides markdown rendering logic.

processor = Qiita::Markdown::Processor.new(hostname: "example.com")
processor.call(markdown)
# => {
#   codes: [
#     {
#       code: "1 + 1\n",
#       language: "ruby",
#       filename: "example.rb",
#     },
#   ],
#   mentioned_usernames: [
#     "alice",
#     "bob",
#   ],
#   output: "<h1>Example</h1>\n...",
# }

Filters

Qiita::Markdown is built on jch/html-pipeline. Add your favorite html-pipeline-compatible filters.

processor = Qiita::Markdown::Processor.new(hostname: "example.com")
processor.filters << HTML::Pipeline::ImageMaxWidthFilter
processor.call(text)

Context

.new and #call can take optional context as a Hash with following keys:

:allowed_usernames            - A list of usernames allowed to be username. (Array<String>)
:asset_path                   - URL path to link to emoji sprite. (String)
:asset_root                   - Base URL to link to emoji sprite. (String)
:base_url                     - Used to construct links to user profile pages for each. (String)
:default_language             - Default language used if no language detected from code. (String)
:emoji_names                  - A list of allowed emoji names. (Array<String>)
:emoji_url_generator          - #call'able object that accepts emoji name as argument and returns emoji image URL. (#call)
                                The original implementation is used when the generator returned a falsey value.
:hostname                     - FQDN. Used to check whether or not each URL of `href` attributes is external site. (String)
:inline_code_color_class_name - Class name for inline code color. (String)
:language_aliases             - Alias table for some language names. (Hash)
:markdown                     - A hash for enabling / disabling optional Markdown syntax. (Hash)
                                Currently only :footnotes (default: true) is supported.
:rule                         - Sanitization rule table. (Hash)
:script                       - A flag to allow to embed script element. (Boolean)
processor = Qiita::Markdown::Processor.new(asset_root: "http://example.com/assets", hostname: "example.com")
processor.call(text)

Rendering Summary

There's another processor Qiita::Markdown::SummaryProcessor, which is for rendering a summary of markdown document. It simplifies a document by removing complex markups and also truncates it to a specific length without breaking the document structure.

Note that this processor does not produce the :codes output in contrast to the Processor.

Context

SummaryProcessor accepts the following context in addition to the Processor's context:

{
  truncate: {
    length: 100,  # Documents will be truncated if it exceeds this character count. (Integer)
    omission: '…' # A string added to the end of document when it's truncated. (String, nil)
  }
}
processor = Qiita::Markdown::SummaryProcessor.new(truncate: { length: 80 }, hostname: "example.com")
processor.call(text)



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
terrylinooo/githuber-md: Markdown editor plugin for WordPress.发布时间:2022-08-18
下一篇:
awalgarg/cv-maker: simple elegant markdown based resumes发布时间:2022-08-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap