tarzan / try_git

0 stars 0 forks source link

Trying code blocks in markdown #1

Open tarzan opened 1 year ago

tarzan commented 1 year ago

This is markdown underline: underlined

This is ==highlighted==

This is a "quote"

def method
  user.destroy
end
def method
  user.destroy
end
\int_{a}^{b} x^2 \,dx
# frozen_string_literal: true

module R::MarkdownHelper
  def self.markdown(text)
    return "" unless text

    options = {
      escape_html: true
    }

    renderer = R::Markdown::ChapterRenderer.new(options)
    markdown = Redcarpet::Markdown.new(renderer, default_markdown_extensions)

    markdown.render(text).html_safe
  end

  def self.excerpt(md, truncate_at = 400, truncate_options = {})
    truncate_options.reverse_update({ separator: /\s/ })

    markdown = Redcarpet::Markdown.new(R::Markdown::ExcerptRenderer, default_markdown_extensions)

    markdown.render(md).truncate(truncate_at, truncate_options)
  end

  def self.plain_markdown(text)
    return "" unless text

    extensions = {
      no_intra_emphasis: true,
      autolink: true,
      superscript: false,
      disable_indented_code_blocks: true,
      fenced_code_blocks: false,
      strikethrough: true,
      lax_spacing: true
    }

    options = { filter_html: true, no_images: true }

    renderer = Redcarpet::Render::HTML.new(options)
    markdown = Redcarpet::Markdown.new(renderer, extensions)
    markdown.render(text).html_safe
  end

  def self.plain_markdown_with_newlines(text)
    return "" unless text

    extensions = {
      no_intra_emphasis: true,
      autolink: true,
      superscript: false,
      disable_indented_code_blocks: true,
      fenced_code_blocks: false,
      strikethrough: true,
      lax_spacing: true
    }

    options = { filter_html: true, hard_wrap: true, no_images: true }

    renderer = Redcarpet::Render::HTML.new(options)
    markdown = Redcarpet::Markdown.new(renderer, extensions)
    markdown.render(text).html_safe
  end

  private

  def self.default_markdown_extensions
    {
      autolink: true,
      disable_indented_code_blocks: true,
      fenced_code_blocks: true,
      lax_spacing: true,
      no_intra_emphasis: true,
      strikethrough: true,
      superscript: true,
      tables: true,
      underline: true,
      highlight: true,
      quote: true
    }
  end
end
tarzan commented 2 months ago

linking with target blank:

Klik hier Klik hier{:target="_blank"} Klik hier