• Stars
    star
    383
  • Rank 111,995 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Qiita-specified markdown processor.

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
  • Note notation's custom block

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 :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)
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)

More Repositories

1

kobito-oss

Markdown Processor built on Electron based on kobito-for-windows
CoffeeScript
202
star
2

qiita-rb

Qiita API v2 client library and CLI tool, written in Ruby
Ruby
150
star
3

qiita-discussions

Discussion of opinions and requests for qiita.com
74
star
4

qiita-js

Qiita API v2 client for browser and node
JavaScript
49
star
5

simplecov-parallel

Parallelism support for SimpleCov, currently only for CircleCI 1.0
Ruby
32
star
6

qiita-coat

The UI components for Qiita.
CSS
30
star
7

vscode-qiita

Qiita theme for VSCode
29
star
8

react_phoenix

Phoenix Template Engine for React (WIP)
Elixir
26
star
9

es-query-builder

A query builder for Elasticsearch in Ruby.
Ruby
26
star
10

js_rails_routes

Generate a ES6 module that contains Rails routes
Ruby
21
star
11

tasklist.js

Converts tasklist in Markdown.
JavaScript
20
star
12

Qiita-Team-Templates

Shared templates for teams
12
star
13

brwy_rails

Browserify | Watchify on Rails
Ruby
11
star
14

graphql-kaminari_connection

Kaminari based GraphQL pagination
Ruby
11
star
15

circleci-coverage_reporter

Ruby
7
star
16

qiita-popular-items-for-alexa

Generating Qiita Popular Items Feed for Alexa Flash Briefing Skill
JavaScript
7
star
17

dotfiles-for-designers

Our sweeeeet dotfiles
Shell
6
star
18

stylelint-config-qiita

Qiita config for stylelint
CSS
6
star
19

active_interactor

Simple use case interactor for Rails apps based on ActiveModel.
Ruby
5
star
20

atom-qiita-ui

Qiita UI for Atom
CSS
5
star
21

circleci-parallel

Ruby APIs for syncing CircleCI 1.0's parallel nodes and transferring files between the nodes
Ruby
5
star
22

slacken

Translate HTML sources to markup texts for Slack
Ruby
3
star
23

graphql-client-js

A lightweight GraphQL client
TypeScript
3
star
24

qiita-team-services

[DEPRECATED] Official Qiita:Team Services Integration
Ruby
3
star
25

qiita-slide-mode

Includes all the components used in Qiita's Slide Mode.
JavaScript
2
star
26

json_schema_view

View framework that brings Schema-driven Development to Rails view
Ruby
2
star
27

atom-qiita-syntax

Qiita theme syntax for Atom
CSS
2
star
28

increments-schedule

Everything about Increments' schedule
Ruby
1
star
29

isucon5q

Ruby
1
star