在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):vmg/redcarpet开源软件地址(OpenSource Url):https://github.com/vmg/redcarpet开源编程语言(OpenSource Language):C 51.1%开源软件介绍(OpenSource Introduction):Redcarpet is written with sugar, spice and everything niceRedcarpet is a Ruby library for Markdown processing that smells like butterflies and popcorn. This library is written by peopleRedcarpet was written by Vicent Martí. It is maintained by Robin Dupret and Matt Rogers. Redcarpet would not be possible without the Sundown library and its authors (Natacha Porté, Vicent Martí, and its many awesome contributors). You can totally install it as a GemRedcarpet is readily available as a Ruby gem. It will build some native extensions, but the parser is standalone and requires no installed libraries. Starting with Redcarpet 3.0, the minimum required Ruby version is 1.9.2 (or Rubinius in 1.9 mode).
If you need to use it with Ruby 1.8.7, you will have to stick with 2.3.0:
The Redcarpet source is available at GitHub:
And it's like really simple to useThe core of the Redcarpet library is the The # Initializes a Markdown parser
markdown = Redcarpet::Markdown.new(renderer, extensions = {}) Here, the Rendering with the markdown.render("This is *bongos*, indeed.")
# => "<p>This is <em>bongos</em>, indeed.</p>" You can also specify a hash containing the Markdown extensions which the parser will identify. The following extensions are accepted:
Example: markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true) Darling, I packed you a couple renderers for lunchRedcarpet comes with two built-in renderers, All the rendering flags that previously applied only to HTML output have
now been moved to the Redcarpet::Render::HTML.new(render_options = {}) Initializes an HTML renderer. The following flags are available:
Example: renderer = Redcarpet::Render::HTML.new(no_links: true, hard_wrap: true) The When instantiating this render object, you can optionally pass a Redcarpet also includes a plaintext renderer, require 'redcarpet'
require 'redcarpet/render_strip'
markdown = Redcarpet::Markdown.new(Redcarpet::Render::StripDown)
markdown.render("**This** _is_ an [example](http://example.org/).")
# => "This is an example (http://example.org/)." And you can even cook your ownCustom renderers are created by inheriting from an existing renderer. The
built-in renderers, # Create a custom renderer that sets a custom class for block-quotes.
class CustomRender < Redcarpet::Render::HTML
def block_quote(quote)
%(<blockquote class="my-custom-class">#{quote}</blockquote>)
end
end
markdown = Redcarpet::Markdown.new(CustomRender, fenced_code_blocks: true) But new renderers can also be created from scratch by extending the abstract
base class class ManPage < Redcarpet::Render::Base
# you get the drill -- keep going from here
end The following instance methods may be implemented by the renderer: Block-level callsIf the return value of the method is Example: class RenderWithoutCode < Redcarpet::Render::HTML
def block_code(code, language)
nil
end
end
Span-level callsA return value of
Note: When overriding a renderer's method, be sure to return a HTML element with a level that matches the level of that method (e.g. return a block element when overriding a block-level callback). Otherwise, the output may be unexpected. Low level rendering
Header of the documentRendered before any another elements:
Footer of the documentRendered after all the other elements:
Pre/post-processSpecial callback: preprocess or postprocess the whole document before or after the rendering process begins:
You can look at "How to extend the Redcarpet 2 Markdown library?" for some more explanations. Also, now our Pants are much smarterRedcarpet 2 comes with a standalone SmartyPants implementation. It is fully compliant with the original implementation. It is the fastest SmartyPants parser there is, with a difference of several orders of magnitude. The SmartyPants parser can be found in When mixed with a Renderer class, it will override the # Mixin
class HTMLWithPants < Redcarpet::Render::HTML
include Redcarpet::Render::SmartyPants
end
# Standalone
Redcarpet::Render::SmartyPants.render("<p>Oh SmartyPants, you're so crazy...</p>") SmartyPants works on top of already-rendered HTML, and will ignore replacements
inside the content of HTML tags and inside specific HTML blocks such as
What? You really want to mix Markdown renderers?Redcarpet used to be a drop-in replacement for Redcloth. This is no longer the case since version 2 -- it now has its own API, but retains the old name. Yes, that does mean that Redcarpet is not backwards-compatible with the 1.X versions. Each renderer has its own API and its own set of extensions: you should choose one (it doesn't have to be Redcarpet, though that would be great!), write your software accordingly, and force your users to install it. That's the only way to have reliable and predictable Markdown output on your program. Markdown is already ill-specified enough; if you create software that is renderer-independent, the results will be completely unreliable! Still, if major forces (let's say, tornadoes or other natural disasters) force you to keep a Markdown-compatibility layer, Redcarpet also supports this: require 'redcarpet/compat' Requiring the compatibility library will declare a Markdown.new('this is my text').to_html This class renders 100% standards compliant Markdown with 0 extensions. Nada. Don't even try to enable extensions with a compatibility layer, because that's a maintenance nightmare and won't work. On a related topic: if your Markdown gem has a Boring legal stuffCopyright (c) 2011-2016, Vicent Martí Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论