<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          HTML-PipelineHTML 格式轉(zhuǎn)換過濾器

          聯(lián)合創(chuàng)作 · 2023-10-02 02:38

          HTML-Pipeline 是一個輕量級框架,可用于將用戶的內(nèi)容轉(zhuǎn)換為 HTML 格式。

          HTML-Pipeline 提供了一些可鏈接的、基于 DOM 的 HTML 過濾器,且支持將過濾器組成管道。

          用法

          過濾器采用 HTML 字符串或 Nokogiri::HTML::DocumentFragment,可以對內(nèi)容進行操作,然后輸出對應(yīng)的結(jié)果。

          如,將 Markdown 源代碼轉(zhuǎn)換為 Markdown HTML :

          require 'html/pipeline'
          
          filter = HTML::Pipeline::MarkdownFilter.new("Hi **world**!")
          filter.call
          

          過濾器可以組合成一個管道,每個過濾器將輸出傳遞給下一個過濾器的輸入。如果你想讓內(nèi)容通過 Markdown 過濾且語法突出顯示,可以創(chuàng)建以下管道:

          pipeline = HTML::Pipeline.new [
            HTML::Pipeline::MarkdownFilter,
            HTML::Pipeline::SyntaxHighlightFilter
          ]
          result = pipeline.call <<-CODE
          This is *great*:
          
              some_code(:first)
          
          CODE
          result[:output].to_s

          輸出:

          <p>This is <em>greatem>:p>
          
          <pre><code>some_code(:first)
          code>pre>

          如果要為 HTML 格式的代碼生成 CSS,請使用 Rouge CSS Theme #css方法。rougeSyntaxHighlightFilter的依賴項。

          有些過濾器接受可選的上下文 且/或 結(jié)果 哈希,用于在管道中的過濾器之間傳遞參數(shù)和元數(shù)據(jù)。例如,如果你不想使用 GitHub 格式的 Markdown,可以在上下文哈希中傳遞一個選項:

          filter = HTML::Pipeline::MarkdownFilter.new("Hi **world**!", :gfm => false)
          filter.call
          

          用例

          為應(yīng)用的不同部分定義不同的管道。

          # The context hash is how you pass options between different filters.
          # See individual filter source for explanation of options.
          context = {
            :asset_root => "http://your-domain.com/where/your/images/live/icons",
            :base_url   => "http://your-domain.com"
          }
          
          # Pipeline providing sanitization and image hijacking but no mention
          # related features.
          SimplePipeline = Pipeline.new [
            SanitizationFilter,
            TableOfContentsFilter, # add 'name' anchors to all headers and generate toc list
            CamoFilter,
            ImageMaxWidthFilter,
            SyntaxHighlightFilter,
            EmojiFilter,
            AutolinkFilter
          ], context
          
          # Pipeline used for user provided content on the web
          MarkdownPipeline = Pipeline.new [
            MarkdownFilter,
            SanitizationFilter,
            CamoFilter,
            ImageMaxWidthFilter,
            HttpsFilter,
            MentionFilter,
            EmojiFilter,
            SyntaxHighlightFilter
          ], context.merge(:gfm => true) # enable github formatted markdown
          
          
          # Define a pipeline based on another pipeline's filters
          NonGFMMarkdownPipeline = Pipeline.new(MarkdownPipeline.filters,
            context.merge(:gfm => false))
          
          # Pipelines aren't limited to the web. You can use them for email
          # processing also.
          HtmlEmailPipeline = Pipeline.new [
            PlainTextInputFilter,
            ImageMaxWidthFilter
          ], {}
          
          # Just emoji.
          EmojiPipeline = Pipeline.new [
            PlainTextInputFilter,
            EmojiFilter
          ], context
          瀏覽 19
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  一本道无码在线观看 | 国产精品色哟 | 五月青春操 | 视频亚洲无码 | 无人区乱码1区2区3区在线 |