app/models/user.rb

    A snippet() snippet

    snippet() is a SQLite function that returns a snippet of text containing the search term. It’s used to highlight search results. This example shows an ActiveRecord scope that enables selection additional fields title_snippet and body_snippet from an FTS5 virtual table (created separately).

    https://www.sqlite.org/fts5.html#the_snippet_function

    app/models/page.rb
    scope :with_snippets do
      select("pages.*")
        .select("snippet(pages_search_index, 0, '<mark>', '</mark>', '…', 32) AS title_snippet")
        .select("snippet(pages_search_index, 1, '<mark>', '</mark>', '…', 32) AS body_snippet")
    end
    Published: · Updated:

    Markdown ASTs with Commonmarker

    For converting Markdown, Rubyists may default to Redcarpet or Kramdown. I suggest taking a look at Commonmarker, a Ruby gem built on top of comrak, a Rust of implementation the GitHub-flavored version of the CommonMark spec.

    Why? One reason is you can parse Markdown into an abstract syntax tree (AST) which enables powerful customization of what you can do with the markdown source.

    require 'commonmarker'
    Commonmarker.to_html('"Hi *there*"', options: {
        parse: { smart: true }
    })
    # => <p>“Hi <em>there</em>”</p>\n
    
    doc = Commonmarker.parse("*Hello* world", options: {
        parse: { smart: true }
    })
    doc.walk do |node|
      puts node.type # => [:document, :paragraph, :emph, :text, :text]
    end
    Published: · Updated:

    Vite on Rails

    An open secret about Rails and JavaScript: lots of apps are using Vite to bundle frontend assets via the excellent Rails integration provided by Vite Ruby. You may want to give it a try. #rails #vite

    bundle add vite_rails
    bundle exec vite install
    Published: · Updated: