Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying code blocks in markdown #1

Open
tarzan opened this issue Jul 7, 2023 · 1 comment
Open

Trying code blocks in markdown #1

tarzan opened this issue Jul 7, 2023 · 1 comment

Comments

@tarzan
Copy link
Owner

tarzan commented Jul 7, 2023

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
Copy link
Owner Author

tarzan commented Aug 22, 2024

linking with target blank:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant