Convert Figma logo to code with AI

github logomarkup

Determines which markup library to use to render a content file (e.g. README) on GitHub

5,833
3,400
5,833
223

Top Related Projects

12,111

Language Savant. If your repository's language is being reported incorrectly, send us a pull request!

CommonMark spec, with reference implementations in C and JavaScript

HTML processing filters and utilities

The safe Markdown parser, reloaded.

kramdown is a fast, pure Ruby Markdown superset converter, using a strict syntax definition and supporting several common extensions.

Blackfriday: a markdown processor for Go

Quick Overview

GitHub Markup is a library used by GitHub to render various markup languages into HTML. It supports multiple formats including Markdown, reStructuredText, textile, and others. This library is used internally by GitHub to render README files and other documentation in repositories.

Pros

  • Supports multiple markup languages
  • Used and maintained by GitHub, ensuring reliability and regular updates
  • Easy integration with Ruby projects
  • Provides a consistent rendering experience across different markup formats

Cons

  • Limited to supported markup languages
  • May not support all features of each markup language
  • Primarily designed for GitHub's internal use, which may limit its flexibility for other applications
  • Requires Ruby runtime environment

Code Examples

Here are a few examples of how to use GitHub Markup:

  1. Rendering Markdown to HTML:
require 'github/markup'
markdown_content = "# Hello, World!\n\nThis is a **bold** text."
html_output = GitHub::Markup.render('README.md', markdown_content)
puts html_output
  1. Rendering reStructuredText to HTML:
require 'github/markup'
rst_content = "Hello, World!\n=============\n\nThis is a *emphasized* text."
html_output = GitHub::Markup.render('README.rst', rst_content)
puts html_output
  1. Detecting the markup format from file content:
require 'github/markup'
file_content = "# Markdown Header\n\nSome content here."
format = GitHub::Markup.format_from_filename('unknown.file', file_content)
puts format

Getting Started

To use GitHub Markup in your Ruby project:

  1. Install the gem:
gem install github-markup
  1. Require the library in your Ruby script:
require 'github/markup'
  1. Use the render method to convert markup to HTML:
content = File.read('README.md')
html_output = GitHub::Markup.render('README.md', content)
puts html_output

This will render the content of README.md as HTML.

Competitor Comparisons

12,111

Language Savant. If your repository's language is being reported incorrectly, send us a pull request!

Pros of Linguist

  • More comprehensive language detection and classification
  • Supports syntax highlighting for a wider range of languages
  • Actively maintained with frequent updates

Cons of Linguist

  • Larger and more complex codebase
  • Potentially slower performance due to extensive language analysis
  • Steeper learning curve for contributors

Code Comparison

Markup (Ruby):

def load(filename)
  content = File.read(filename)
  renderer = self.renderer(filename)
  renderer.render(content)
end

Linguist (Ruby):

def detect_language(blob)
  data = blob.data
  Samples.each do |sample|
    return sample.language if sample.matches?(data)
  end
  Language['Text']
end

Key Differences

  • Markup focuses on rendering various markup formats
  • Linguist specializes in language detection and classification
  • Linguist has a more extensive database of language samples
  • Markup is simpler and more lightweight for basic markup tasks
  • Linguist offers more advanced features for language analysis

Use Cases

  • Markup: Ideal for projects needing simple markup rendering
  • Linguist: Better suited for applications requiring accurate language detection and syntax highlighting across many languages

CommonMark spec, with reference implementations in C and JavaScript

Pros of commonmark-spec

  • Provides a standardized Markdown specification, ensuring consistency across implementations
  • Extensive test suite for validating CommonMark parsers
  • Detailed documentation and rationale for design decisions

Cons of commonmark-spec

  • Focuses solely on specification, lacking a ready-to-use implementation
  • May not cover all Markdown extensions used in various platforms
  • Slower to adopt new features due to the rigorous standardization process

Code Comparison

markup:

def markup(content)
  GitHub::Markup.render(file, content)
end

commonmark-spec:

const commonmark = require('commonmark');
const reader = new commonmark.Parser();
const writer = new commonmark.HtmlRenderer();
const parsed = reader.parse(markdown);
const result = writer.render(parsed);

Summary

markup is a practical library for rendering various markup languages, including Markdown, while commonmark-spec focuses on standardizing Markdown syntax. markup offers immediate usability for multiple formats, whereas commonmark-spec provides a robust foundation for consistent Markdown parsing across different implementations. The choice between them depends on whether you need a ready-to-use solution for multiple formats or a standardized Markdown specification for developing parsers.

HTML processing filters and utilities

Pros of html-pipeline

  • More modular and extensible architecture, allowing for easy customization and addition of new filters
  • Supports a wider range of input formats and output transformations
  • Better suited for complex content processing pipelines

Cons of html-pipeline

  • Steeper learning curve due to its more complex architecture
  • May be overkill for simpler markup conversion tasks
  • Requires more setup and configuration compared to markup

Code Comparison

markup:

GitHub::Markup.render('README.md', File.read('README.md'))

html-pipeline:

pipeline = HTML::Pipeline.new([
  HTML::Pipeline::MarkdownFilter,
  HTML::Pipeline::SanitizationFilter
])
result = pipeline.call(File.read('README.md'))

The code comparison shows that markup offers a simpler, one-line approach for basic rendering, while html-pipeline provides a more flexible, multi-step processing pipeline.

Both repositories serve different purposes and cater to different use cases. markup is better suited for quick and simple markup conversions, while html-pipeline excels in scenarios requiring complex content processing and transformation pipelines. The choice between the two depends on the specific requirements of the project and the level of customization needed.

The safe Markdown parser, reloaded.

Pros of Redcarpet

  • Faster performance for Markdown parsing and rendering
  • More extensive Markdown syntax support, including tables and fenced code blocks
  • Customizable with various extensions and render options

Cons of Redcarpet

  • Limited to Markdown processing, while Markup supports multiple formats
  • Less actively maintained, with fewer recent updates
  • May require more setup and configuration for specific use cases

Code Comparison

Redcarpet:

markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
html = markdown.render("# Hello World")

Markup:

GitHub::Markup.render("README.md", "# Hello World")

Key Differences

Markup is a more versatile library that supports multiple markup languages, including Markdown, reStructuredText, and Textile. It's designed to be used as a general-purpose markup processor for various file types.

Redcarpet, on the other hand, is specifically focused on Markdown processing. It offers more advanced Markdown features and customization options, making it a better choice for projects that primarily deal with Markdown content.

Markup is actively maintained by GitHub and integrates well with their ecosystem, while Redcarpet has seen less frequent updates in recent years.

Choose Markup for multi-format support and GitHub integration, or Redcarpet for specialized Markdown processing with enhanced performance and features.

kramdown is a fast, pure Ruby Markdown superset converter, using a strict syntax definition and supporting several common extensions.

Pros of kramdown

  • More comprehensive Markdown support, including extensions like tables and definition lists
  • Highly configurable with various parsing and conversion options
  • Actively maintained with regular updates and improvements

Cons of kramdown

  • Slower parsing speed compared to markup, especially for large documents
  • Steeper learning curve due to its extensive feature set
  • May require additional setup for certain advanced features

Code Comparison

kramdown:

require 'kramdown'

doc = Kramdown::Document.new('# Hello World')
puts doc.to_html

markup:

require 'github/markup'

puts GitHub::Markup.render('file.md', '# Hello World')

Summary

kramdown offers a more feature-rich Markdown processing experience with extensive configuration options, making it suitable for complex document conversion tasks. However, it may be overkill for simpler projects and can be slower than markup for large documents.

markup, on the other hand, provides a straightforward interface for rendering various markup languages, including Markdown. It's designed to be fast and easy to use, but lacks some of the advanced features and customization options found in kramdown.

Choose kramdown for projects requiring advanced Markdown features and customization, and markup for simpler, performance-critical applications or when working with multiple markup languages.

Blackfriday: a markdown processor for Go

Pros of Blackfriday

  • Faster performance for Markdown parsing and rendering
  • More extensive Markdown feature support, including tables and footnotes
  • Written in Go, making it easy to integrate with Go-based applications

Cons of Blackfriday

  • Limited to Markdown only, while Markup supports multiple markup languages
  • Less actively maintained compared to Markup
  • May require more setup and configuration for non-Go projects

Code Comparison

Blackfriday (Go):

import "github.com/russross/blackfriday/v2"

markdown := []byte("# Hello, World!")
html := blackfriday.Run(markdown)

Markup (Ruby):

require 'github/markup'

markdown = "# Hello, World!"
html = GitHub::Markup.render('README.md', markdown)

Summary

Blackfriday is a Go-based Markdown parser with excellent performance and feature support, ideal for Go projects. Markup, on the other hand, is a Ruby-based library that supports multiple markup languages, making it more versatile for projects using various formats. Blackfriday excels in Markdown-specific use cases, while Markup offers broader language support at the cost of some performance. The choice between the two depends on the project's requirements, programming language, and desired markup language support.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

GitHub Markup

This library is the first step of a journey that every markup file in a repository goes on before it is rendered on GitHub.com:

  1. github-markup selects an underlying library to convert the raw markup to HTML. See the list of supported markup formats below.
  2. The HTML is sanitized, aggressively removing things that could harm you and your kin—such as script tags, inline-styles, and class or id attributes.
  3. Syntax highlighting is performed on code blocks. See github/linguist for more information about syntax highlighting.
  4. The HTML is passed through other filters that add special sauce, such as emoji, task lists, named anchors, CDN caching for images, and autolinking.
  5. The resulting HTML is rendered on GitHub.com.

Please note that only the first step is covered by this gem — the rest happens on GitHub.com. In particular, markup itself does no sanitization of the resulting HTML, as it expects that to be covered by whatever pipeline is consuming the HTML.

Please see our contributing guidelines before reporting an issue.

Markups

The following markups are supported. The dependencies listed are required if you wish to run the library. You can also run script/bootstrap to fetch them all.

Installation

gem install github-markup

or

bundle install

from this directory.

Usage

Basic form:

require 'github/markup'

GitHub::Markup.render('README.markdown', "* One\n* Two")

More realistic form:

require 'github/markup'

GitHub::Markup.render(file, File.read(file))

And a convenience form:

require 'github/markup'

GitHub::Markup.render_s(GitHub::Markups::MARKUP_MARKDOWN, "* One\n* Two")

Local Development

python3 -m venv .venv
source .venv/bin/activate
cd script
./bootstrap

Contributing

See Contributing.