Zettelkasten Forum


Hide UID in title when previewed with Marked 2

Hi,

I write my note title as follow : # date-based-uid note title. But I also have notes titled without UID.

I use Marked 2 app to preview/export my notes. My goal is to make Marked 2 hide the UID in the title when previewed.

I think it is possible to reach the goal as follow:

  1. Write a preprocessor script for Marked 2, which add a span html tag around UID only when there is an UID in h1 tag (the title)
  2. Hide h1 span in the CSS theme, so that we only see the note title without the UID

Can someone help me write a simple Marked 2 preprocessor script for that?

Comments

  • I found a solution for the following expected behavior in Marked 2 app:

    When (and only when) I preview a note containing UID in title (like # 202004061230 Title note), the UID is removed in Marked 2.

    1. Create a ruby file (.rb) with the following code:
    #!/usr/bin/env ruby
    
    begin
      input = STDIN.read.force_encoding('utf-8')
    rescue
      input = STDIN.read
    end
    
    class String
      def remove_first_line!
        first_newline = (index("\n") || size - 1) + 1
        slice!(0, first_newline).sub("\n",'')
      end
    end
    
    title = input.remove_first_line!
    
    title.gsub!(/[0-9]{12}/) do |m|
      match = Regexp.last_match
      uid = match[1]
      "<span>#{uid}</span>"
    end
    
    input = title + "\n" + input
    print input
    
    1. Add the file as Marked 2 preprocessor (like this

    2. Add in the theme (css file) #wrapper h1 span {display: none;}

    I don't know at all Ruby, I wrote this code quickly after some Internet search, so it can surely be simplified and optimized.

  • Update with a much simpler solution:

    1. Create a ruby file with the following code
    #!/usr/bin/env ruby
    
    begin
      input = STDIN.read.force_encoding('utf-8')
    rescue
      input = STDIN.read
    end
    
    input = input.gsub(/^#\s[0-9]{12}/, "#")
    
    print input
    
    
    1. Add the file as Marked 2 preprocessor

    That's all.

Sign In or Register to comment.