Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/increments/qiita-markdown
Qiita-specified markdown processor.
https://github.com/increments/qiita-markdown
Last synced: 13 days ago
JSON representation
Qiita-specified markdown processor.
- Host: GitHub
- URL: https://github.com/increments/qiita-markdown
- Owner: increments
- License: mit
- Created: 2014-10-01T09:23:58.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-04-10T08:46:18.000Z (7 months ago)
- Last Synced: 2024-09-25T11:25:35.157Z (about 2 months ago)
- Language: Ruby
- Homepage:
- Size: 407 KB
- Stars: 394
- Watchers: 41
- Forks: 31
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Qiita Markdown
[![Gem Version](https://badge.fury.io/rb/qiita-markdown.svg)](https://badge.fury.io/rb/qiita-markdown)
[![Build Status](https://travis-ci.org/increments/qiita-markdown.svg)](https://travis-ci.org/increments/qiita-markdown)
[![Code Climate](https://codeclimate.com/github/increments/qiita-markdown/badges/gpa.svg)](https://codeclimate.com/github/increments/qiita-markdown)
[![Test Coverage](https://codeclimate.com/github/increments/qiita-markdown/badges/coverage.svg)](https://codeclimate.com/github/increments/qiita-markdown)Qiita-specified markdown processor.
- Markdown conversion
- Sanitization
- Code and language detection
- Task list
- ToC
- Emoji
- Syntax highlighting
- Mention
- Footnotes
- Note notation's custom block## Basic Usage
Qiita::Markdown::Processor provides markdown rendering logic.
```ruby
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: "Example
\n...",
# }
```### Filters
Qiita Markdown is built on [jch/html-pipeline](https://github.com/jch/html-pipeline).
Add your favorite html-pipeline-compatible filters.```ruby
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)
: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)
: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 :footnotes (default: true) and :sourcepos (defalut: false) are supported.
For more information on these options, please see [increments/qiita_marker](https://github.com/increments/qiita_marker).
:rule - Sanitization rule table. (Hash)
:script - A flag to allow to embed script element. (Boolean)
``````ruby
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:
```ruby
{
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)
}
}
``````ruby
processor = Qiita::Markdown::SummaryProcessor.new(truncate: { length: 80 }, hostname: "example.com")
processor.call(text)
```