mdless 2.0.12 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +3 -2
 - data/lib/mdless/colors.rb +0 -56
 - data/lib/mdless/console.rb +72 -4
 - data/lib/mdless/converter.rb +47 -8
 - data/lib/mdless/taskpaper.rb +77 -0
 - data/lib/mdless/theme.rb +11 -1
 - data/lib/mdless/version.rb +1 -1
 - data/lib/mdless.rb +1 -0
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 863102e504ba07c2ab9b018687d50053ca3395206666d1abffcf79997023db9e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: bbba927ea37503308dac7356cb2d72e84e4cf53c5cf28f3f2b210c68b745cbf1
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 92d0edc1d4722074e897981138c585a02fb9c287c8e8fc270885cc19b6274a2490bcd69b92c198c9876d4c4c1bf9b0ec0226c0e97660791fbfdf6c8e85f5592b
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: d738066449abc9ee9a8d0331b6ef64db675686cc53c9d0bbf3fa320a63a70c9f33312e0a6fe6c7055caffca7ba13deefcce10ee57f7e3fd7e291a8447e9674fd
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -58,15 +58,16 @@ The pager used is determined by system configuration in this order of preference 
     | 
|
| 
       58 
58 
     | 
    
         
             
                -c, --[no-]color                 Colorize output (default on)
         
     | 
| 
       59 
59 
     | 
    
         
             
                -d, --debug LEVEL                Level of debug messages to output (1-4, 4 to see all messages)
         
     | 
| 
       60 
60 
     | 
    
         
             
                -h, --help                       Display this screen
         
     | 
| 
       61 
     | 
    
         
            -
                -i, --images=TYPE                Include [local|remote (both)] images in output (requires chafa or imgcat, default  
     | 
| 
      
 61 
     | 
    
         
            +
                -i, --images=TYPE                Include [local|remote (both)|none] images in output (requires chafa or imgcat, default none).
         
     | 
| 
       62 
62 
     | 
    
         
             
                -I, --all-images                 Include local and remote images in output (requires imgcat or chafa)
         
     | 
| 
       63 
63 
     | 
    
         
             
                    --syntax                     Syntax highlight code blocks
         
     | 
| 
       64 
     | 
    
         
            -
                    --links=FORMAT               Link style ([inline, reference], default inline 
     | 
| 
      
 64 
     | 
    
         
            +
                    --links=FORMAT               Link style ([inline, reference, paragraph], default inline, "paragraph" will position reference links after each paragraph)
         
     | 
| 
       65 
65 
     | 
    
         
             
                -l, --list                       List headers in document and exit
         
     | 
| 
       66 
66 
     | 
    
         
             
                -p, --[no-]pager                 Formatted output to pager (default on)
         
     | 
| 
       67 
67 
     | 
    
         
             
                -P                               Disable pager (same as --no-pager)
         
     | 
| 
       68 
68 
     | 
    
         
             
                -s, --section=NUMBER[,NUMBER]    Output only a headline-based section of the input (numeric from --list)
         
     | 
| 
       69 
69 
     | 
    
         
             
                -t, --theme=THEME_NAME           Specify an alternate color theme to load
         
     | 
| 
      
 70 
     | 
    
         
            +
                -@, --at_tags                    Highlight @tags and values in the document
         
     | 
| 
       70 
71 
     | 
    
         
             
                -v, --version                    Display version number
         
     | 
| 
       71 
72 
     | 
    
         
             
                -w, --width=COLUMNS              Column width to format for (default: terminal width)
         
     | 
| 
       72 
73 
     | 
    
         
             
                    --[no-]inline_footnotes      Display footnotes immediately after the paragraph that references them
         
     | 
    
        data/lib/mdless/colors.rb
    CHANGED
    
    | 
         @@ -114,62 +114,6 @@ module CLIMarkdown 
     | 
|
| 
       114 
114 
     | 
    
         
             
                  escape + "\e[#{[fg, bg].delete_if(&:nil?).join(';')}m"
         
     | 
| 
       115 
115 
     | 
    
         
             
                end
         
     | 
| 
       116 
116 
     | 
    
         | 
| 
       117 
     | 
    
         
            -
                # Get the calculated ANSI color at the end of the
         
     | 
| 
       118 
     | 
    
         
            -
                # string
         
     | 
| 
       119 
     | 
    
         
            -
                #
         
     | 
| 
       120 
     | 
    
         
            -
                # @return     ANSI escape sequence to match color
         
     | 
| 
       121 
     | 
    
         
            -
                #
         
     | 
| 
       122 
     | 
    
         
            -
                def last_color_code
         
     | 
| 
       123 
     | 
    
         
            -
                  m = scan(ESCAPE_REGEX)
         
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
                  em = ['0']
         
     | 
| 
       126 
     | 
    
         
            -
                  fg = nil
         
     | 
| 
       127 
     | 
    
         
            -
                  bg = nil
         
     | 
| 
       128 
     | 
    
         
            -
                  rgbf = nil
         
     | 
| 
       129 
     | 
    
         
            -
                  rgbb = nil
         
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
                  m.each do |c|
         
     | 
| 
       132 
     | 
    
         
            -
                    case c
         
     | 
| 
       133 
     | 
    
         
            -
                    when '0'
         
     | 
| 
       134 
     | 
    
         
            -
                      em = ['0']
         
     | 
| 
       135 
     | 
    
         
            -
                      fg, bg, rgbf, rgbb = nil
         
     | 
| 
       136 
     | 
    
         
            -
                    when /^[34]8/
         
     | 
| 
       137 
     | 
    
         
            -
                      case c
         
     | 
| 
       138 
     | 
    
         
            -
                      when /^3/
         
     | 
| 
       139 
     | 
    
         
            -
                        fg = nil
         
     | 
| 
       140 
     | 
    
         
            -
                        rgbf = c
         
     | 
| 
       141 
     | 
    
         
            -
                      when /^4/
         
     | 
| 
       142 
     | 
    
         
            -
                        bg = nil
         
     | 
| 
       143 
     | 
    
         
            -
                        rgbb = c
         
     | 
| 
       144 
     | 
    
         
            -
                      end
         
     | 
| 
       145 
     | 
    
         
            -
                    else
         
     | 
| 
       146 
     | 
    
         
            -
                      c.split(/;/).each do |i|
         
     | 
| 
       147 
     | 
    
         
            -
                        x = i.to_i
         
     | 
| 
       148 
     | 
    
         
            -
                        if x <= 9
         
     | 
| 
       149 
     | 
    
         
            -
                          em << x
         
     | 
| 
       150 
     | 
    
         
            -
                        elsif x >= 30 && x <= 39
         
     | 
| 
       151 
     | 
    
         
            -
                          rgbf = nil
         
     | 
| 
       152 
     | 
    
         
            -
                          fg = x
         
     | 
| 
       153 
     | 
    
         
            -
                        elsif x >= 40 && x <= 49
         
     | 
| 
       154 
     | 
    
         
            -
                          rgbb = nil
         
     | 
| 
       155 
     | 
    
         
            -
                          bg = x
         
     | 
| 
       156 
     | 
    
         
            -
                        elsif x >= 90 && x <= 97
         
     | 
| 
       157 
     | 
    
         
            -
                          rgbf = nil
         
     | 
| 
       158 
     | 
    
         
            -
                          fg = x
         
     | 
| 
       159 
     | 
    
         
            -
                        elsif x >= 100 && x <= 107
         
     | 
| 
       160 
     | 
    
         
            -
                          rgbb = nil
         
     | 
| 
       161 
     | 
    
         
            -
                          bg = x
         
     | 
| 
       162 
     | 
    
         
            -
                        end
         
     | 
| 
       163 
     | 
    
         
            -
                      end
         
     | 
| 
       164 
     | 
    
         
            -
                    end
         
     | 
| 
       165 
     | 
    
         
            -
                  end
         
     | 
| 
       166 
     | 
    
         
            -
             
     | 
| 
       167 
     | 
    
         
            -
                  escape = "\e[#{em.join(';')}m"
         
     | 
| 
       168 
     | 
    
         
            -
                  escape += "\e[#{rgbb}m" if rgbb
         
     | 
| 
       169 
     | 
    
         
            -
                  escape += "\e[#{rgbf}m" if rgbf
         
     | 
| 
       170 
     | 
    
         
            -
                  escape + "\e[#{[fg, bg].delete_if(&:nil?).join(';')}m"
         
     | 
| 
       171 
     | 
    
         
            -
                end
         
     | 
| 
       172 
     | 
    
         
            -
             
     | 
| 
       173 
117 
     | 
    
         
             
                def blackout(bgcolor)
         
     | 
| 
       174 
118 
     | 
    
         
             
                  key = bgcolor.to_sym
         
     | 
| 
       175 
119 
     | 
    
         
             
                  bg = COLORS.key?(key) ? COLORS[key] : 40
         
     | 
    
        data/lib/mdless/console.rb
    CHANGED
    
    | 
         @@ -3,6 +3,7 @@ module Redcarpet 
     | 
|
| 
       3 
3 
     | 
    
         
             
                class Console < Base
         
     | 
| 
       4 
4 
     | 
    
         
             
                  include CLIMarkdown::Colors
         
     | 
| 
       5 
5 
     | 
    
         
             
                  include CLIMarkdown::Theme
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       6 
7 
     | 
    
         
             
                  attr_writer :theme, :cols, :log, :options, :file
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
9 
     | 
    
         
             
                  @@listitemid = 0
         
     | 
| 
         @@ -550,8 +551,8 @@ module Redcarpet 
     | 
|
| 
       550 
551 
     | 
    
         
             
                    @@headers
         
     | 
| 
       551 
552 
     | 
    
         
             
                  end
         
     | 
| 
       552 
553 
     | 
    
         | 
| 
       553 
     | 
    
         
            -
                  def  
     | 
| 
       554 
     | 
    
         
            -
                     
     | 
| 
      
 554 
     | 
    
         
            +
                  def color_meta(text)
         
     | 
| 
      
 555 
     | 
    
         
            +
                    input = text.dup
         
     | 
| 
       555 
556 
     | 
    
         
             
                    first_line = input.split("\n").first
         
     | 
| 
       556 
557 
     | 
    
         
             
                    if first_line =~ /(?i-m)^---[ \t]*?$/
         
     | 
| 
       557 
558 
     | 
    
         
             
                      @log.info('Found YAML')
         
     | 
| 
         @@ -592,12 +593,38 @@ module Redcarpet 
     | 
|
| 
       592 
593 
     | 
    
         
             
                          line + xc
         
     | 
| 
       593 
594 
     | 
    
         
             
                        end.join("\n") + "#{"\u00A0" * longest}#{xc}\n"
         
     | 
| 
       594 
595 
     | 
    
         
             
                      end
         
     | 
| 
      
 596 
     | 
    
         
            +
                    end
         
     | 
| 
       595 
597 
     | 
    
         | 
| 
      
 598 
     | 
    
         
            +
                    input
         
     | 
| 
      
 599 
     | 
    
         
            +
                  end
         
     | 
| 
      
 600 
     | 
    
         
            +
             
     | 
| 
      
 601 
     | 
    
         
            +
                  def preprocess(input)
         
     | 
| 
      
 602 
     | 
    
         
            +
                    in_yaml = false
         
     | 
| 
      
 603 
     | 
    
         
            +
             
     | 
| 
      
 604 
     | 
    
         
            +
                    if @options[:taskpaper] == :auto
         
     | 
| 
      
 605 
     | 
    
         
            +
                      @options[:taskpaper] = if @file =~ /\.taskpaper/
         
     | 
| 
      
 606 
     | 
    
         
            +
                                               @log.info('TaskPaper extension detected')
         
     | 
| 
      
 607 
     | 
    
         
            +
                                               true
         
     | 
| 
      
 608 
     | 
    
         
            +
                                             elsif CLIMarkdown::TaskPaper.is_taskpaper?(input)
         
     | 
| 
      
 609 
     | 
    
         
            +
                                               @log.info('TaskPaper document detected')
         
     | 
| 
      
 610 
     | 
    
         
            +
                                               true
         
     | 
| 
      
 611 
     | 
    
         
            +
                                             else
         
     | 
| 
      
 612 
     | 
    
         
            +
                                               false
         
     | 
| 
      
 613 
     | 
    
         
            +
                                             end
         
     | 
| 
       596 
614 
     | 
    
         
             
                    end
         
     | 
| 
       597 
615 
     | 
    
         | 
| 
      
 616 
     | 
    
         
            +
                    input = color_meta(input)
         
     | 
| 
      
 617 
     | 
    
         
            +
             
     | 
| 
      
 618 
     | 
    
         
            +
                    if @options[:taskpaper]
         
     | 
| 
      
 619 
     | 
    
         
            +
                      input = CLIMarkdown::TaskPaper.highlight(input, @theme)
         
     | 
| 
      
 620 
     | 
    
         
            +
                      input = highlight_tags(input)
         
     | 
| 
      
 621 
     | 
    
         
            +
                      return input
         
     | 
| 
      
 622 
     | 
    
         
            +
                    end
         
     | 
| 
      
 623 
     | 
    
         
            +
             
     | 
| 
      
 624 
     | 
    
         
            +
             
     | 
| 
       598 
625 
     | 
    
         
             
                    ## Replace setex headers with ATX
         
     | 
| 
       599 
     | 
    
         
            -
                    input.gsub!(/^([^\n]+)\n={ 
     | 
| 
       600 
     | 
    
         
            -
                    input.gsub!(/^([^\n]+?)\n-{ 
     | 
| 
      
 626 
     | 
    
         
            +
                    input.gsub!(/^([^\n]+)\n={2,}\s*$/m, "# \\1\n")
         
     | 
| 
      
 627 
     | 
    
         
            +
                    input.gsub!(/^([^\n]+?)\n-{2,}\s*$/m, "## \\1\n")
         
     | 
| 
       601 
628 
     | 
    
         | 
| 
       602 
629 
     | 
    
         
             
                    @@headers = get_headers(input)
         
     | 
| 
       603 
630 
     | 
    
         | 
| 
         @@ -808,9 +835,49 @@ module Redcarpet 
     | 
|
| 
       808 
835 
     | 
    
         
             
                    end
         
     | 
| 
       809 
836 
     | 
    
         
             
                  end
         
     | 
| 
       810 
837 
     | 
    
         | 
| 
      
 838 
     | 
    
         
            +
                  def highlight_tags(input)
         
     | 
| 
      
 839 
     | 
    
         
            +
                    tag_color = color('at_tags tag')
         
     | 
| 
      
 840 
     | 
    
         
            +
                    value_color = color('at_tags value')
         
     | 
| 
      
 841 
     | 
    
         
            +
                    input.gsub(/(?<pre>\s|m)(?<tag>@[^ \].?!,("']+)(?:(?<lparen>\()(?<value>.*?)(?<rparen>\)))?/) do
         
     | 
| 
      
 842 
     | 
    
         
            +
                      m = Regexp.last_match
         
     | 
| 
      
 843 
     | 
    
         
            +
                      last_color = m.pre_match.last_color_code
         
     | 
| 
      
 844 
     | 
    
         
            +
                      [
         
     | 
| 
      
 845 
     | 
    
         
            +
                        m['pre'],
         
     | 
| 
      
 846 
     | 
    
         
            +
                        tag_color,
         
     | 
| 
      
 847 
     | 
    
         
            +
                        m['tag'],
         
     | 
| 
      
 848 
     | 
    
         
            +
                        m['lparen'],
         
     | 
| 
      
 849 
     | 
    
         
            +
                        value_color,
         
     | 
| 
      
 850 
     | 
    
         
            +
                        m['value'],
         
     | 
| 
      
 851 
     | 
    
         
            +
                        tag_color,
         
     | 
| 
      
 852 
     | 
    
         
            +
                        m['rparen'],
         
     | 
| 
      
 853 
     | 
    
         
            +
                        xc,
         
     | 
| 
      
 854 
     | 
    
         
            +
                        last_color
         
     | 
| 
      
 855 
     | 
    
         
            +
                      ].join
         
     | 
| 
      
 856 
     | 
    
         
            +
                    end
         
     | 
| 
      
 857 
     | 
    
         
            +
                  end
         
     | 
| 
      
 858 
     | 
    
         
            +
             
     | 
| 
      
 859 
     | 
    
         
            +
                  def highlight_wiki_links(input)
         
     | 
| 
      
 860 
     | 
    
         
            +
                    input.gsub(/\[\[(.*?)\]\]/) do
         
     | 
| 
      
 861 
     | 
    
         
            +
                      content = Regexp.last_match(1)
         
     | 
| 
      
 862 
     | 
    
         
            +
                      [
         
     | 
| 
      
 863 
     | 
    
         
            +
                        pre_element,
         
     | 
| 
      
 864 
     | 
    
         
            +
                        color('link brackets'),
         
     | 
| 
      
 865 
     | 
    
         
            +
                        '[[',
         
     | 
| 
      
 866 
     | 
    
         
            +
                        color('link text'),
         
     | 
| 
      
 867 
     | 
    
         
            +
                        content,
         
     | 
| 
      
 868 
     | 
    
         
            +
                        color('link brackets'),
         
     | 
| 
      
 869 
     | 
    
         
            +
                        ']]',
         
     | 
| 
      
 870 
     | 
    
         
            +
                        xc,
         
     | 
| 
      
 871 
     | 
    
         
            +
                        post_element
         
     | 
| 
      
 872 
     | 
    
         
            +
                      ].join
         
     | 
| 
      
 873 
     | 
    
         
            +
                    end
         
     | 
| 
      
 874 
     | 
    
         
            +
                  end
         
     | 
| 
      
 875 
     | 
    
         
            +
             
     | 
| 
       811 
876 
     | 
    
         
             
                  def postprocess(input)
         
     | 
| 
       812 
877 
     | 
    
         
             
                    input.scrub!
         
     | 
| 
       813 
878 
     | 
    
         | 
| 
      
 879 
     | 
    
         
            +
                    input = highlight_wiki_links(input) if @options[:wiki_links]
         
     | 
| 
      
 880 
     | 
    
         
            +
             
     | 
| 
       814 
881 
     | 
    
         
             
                    if @options[:inline_footnotes]
         
     | 
| 
       815 
882 
     | 
    
         
             
                      input = insert_footnotes(input)
         
     | 
| 
       816 
883 
     | 
    
         
             
                    else
         
     | 
| 
         @@ -832,6 +899,7 @@ module Redcarpet 
     | 
|
| 
       832 
899 
     | 
    
         
             
                    # lists
         
     | 
| 
       833 
900 
     | 
    
         
             
                    input = fix_lists(input, 0)
         
     | 
| 
       834 
901 
     | 
    
         
             
                    input = render_images(input) if @options[:local_images]
         
     | 
| 
      
 902 
     | 
    
         
            +
                    input = highlight_tags(input) if @options[:at_tags] || @options[:taskpaper]
         
     | 
| 
       835 
903 
     | 
    
         
             
                    fix_colors(input)
         
     | 
| 
       836 
904 
     | 
    
         
             
                  end
         
     | 
| 
       837 
905 
     | 
    
         
             
                end
         
     | 
    
        data/lib/mdless/converter.rb
    CHANGED
    
    | 
         @@ -45,7 +45,7 @@ module CLIMarkdown 
     | 
|
| 
       45 
45 
     | 
    
         
             
                    @options[:local_images] ||= false
         
     | 
| 
       46 
46 
     | 
    
         
             
                    @options[:remote_images] ||= false
         
     | 
| 
       47 
47 
     | 
    
         
             
                    opts.on('-i', '--images=TYPE',
         
     | 
| 
       48 
     | 
    
         
            -
                            'Include [local|remote (both)] images in output (requires chafa or imgcat, default  
     | 
| 
      
 48 
     | 
    
         
            +
                            'Include [local|remote (both)|none] images in output (requires chafa or imgcat, default none).') do |type|
         
     | 
| 
       49 
49 
     | 
    
         
             
                      if exec_available('imgcat') || exec_available('chafa')
         
     | 
| 
       50 
50 
     | 
    
         
             
                        case type
         
     | 
| 
       51 
51 
     | 
    
         
             
                        when /^(r|b|a)/i
         
     | 
| 
         @@ -75,6 +75,23 @@ module CLIMarkdown 
     | 
|
| 
       75 
75 
     | 
    
         
             
                      @options[:syntax_higlight] = p
         
     | 
| 
       76 
76 
     | 
    
         
             
                    end
         
     | 
| 
       77 
77 
     | 
    
         | 
| 
      
 78 
     | 
    
         
            +
                    @options[:update_config] ||= false
         
     | 
| 
      
 79 
     | 
    
         
            +
                    opts.on('--update_config', 'Update the configuration file with new keys and current command line options') do
         
     | 
| 
      
 80 
     | 
    
         
            +
                      @options[:update_config] = true
         
     | 
| 
      
 81 
     | 
    
         
            +
                    end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                    @options[:taskpaper] ||= false
         
     | 
| 
      
 84 
     | 
    
         
            +
                    opts.on('--taskpaper=OPTION', 'Highlight TaskPaper format (true|false|auto)') do |tp|
         
     | 
| 
      
 85 
     | 
    
         
            +
                      @options[:taskpaper] = case tp
         
     | 
| 
      
 86 
     | 
    
         
            +
                                             when /^[ty1]/
         
     | 
| 
      
 87 
     | 
    
         
            +
                                               true
         
     | 
| 
      
 88 
     | 
    
         
            +
                                             when /^a/
         
     | 
| 
      
 89 
     | 
    
         
            +
                                               :auto
         
     | 
| 
      
 90 
     | 
    
         
            +
                                             else
         
     | 
| 
      
 91 
     | 
    
         
            +
                                               false
         
     | 
| 
      
 92 
     | 
    
         
            +
                                             end
         
     | 
| 
      
 93 
     | 
    
         
            +
                    end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
       78 
95 
     | 
    
         
             
                    @options[:links] ||= :inline
         
     | 
| 
       79 
96 
     | 
    
         
             
                    opts.on('--links=FORMAT',
         
     | 
| 
       80 
97 
     | 
    
         
             
                            'Link style ([inline, reference, paragraph], default inline, "paragraph" will position reference links after each paragraph)') do |fmt|
         
     | 
| 
         @@ -88,6 +105,16 @@ module CLIMarkdown 
     | 
|
| 
       88 
105 
     | 
    
         
             
                                         end
         
     | 
| 
       89 
106 
     | 
    
         
             
                    end
         
     | 
| 
       90 
107 
     | 
    
         | 
| 
      
 108 
     | 
    
         
            +
                    @options[:lax_spacing] ||= true
         
     | 
| 
      
 109 
     | 
    
         
            +
                    opts.on('--[no-]lax-spacing', 'Allow lax spacing') do |opt|
         
     | 
| 
      
 110 
     | 
    
         
            +
                      @options[:lax_spacing] = opt
         
     | 
| 
      
 111 
     | 
    
         
            +
                    end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                    @options[:intra_emphasis] ||= true
         
     | 
| 
      
 114 
     | 
    
         
            +
                    opts.on('--[no-]intra-emphasis', 'Parse emphasis inside of words (e.g. Mark_down_)') do |opt|
         
     | 
| 
      
 115 
     | 
    
         
            +
                      @options[:intra_emphasis] = opt
         
     | 
| 
      
 116 
     | 
    
         
            +
                    end
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
       91 
118 
     | 
    
         
             
                    @options[:list] ||= false
         
     | 
| 
       92 
119 
     | 
    
         
             
                    opts.on('-l', '--list', 'List headers in document and exit') do
         
     | 
| 
       93 
120 
     | 
    
         
             
                      @options[:list] = true
         
     | 
| 
         @@ -98,6 +125,7 @@ module CLIMarkdown 
     | 
|
| 
       98 
125 
     | 
    
         
             
                      @options[:pager] = p
         
     | 
| 
       99 
126 
     | 
    
         
             
                    end
         
     | 
| 
       100 
127 
     | 
    
         | 
| 
      
 128 
     | 
    
         
            +
                    @options[:pager] ||= true
         
     | 
| 
       101 
129 
     | 
    
         
             
                    opts.on('-P', 'Disable pager (same as --no-pager)') do
         
     | 
| 
       102 
130 
     | 
    
         
             
                      @options[:pager] = false
         
     | 
| 
       103 
131 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -113,6 +141,16 @@ module CLIMarkdown 
     | 
|
| 
       113 
141 
     | 
    
         
             
                      @options[:theme] = theme
         
     | 
| 
       114 
142 
     | 
    
         
             
                    end
         
     | 
| 
       115 
143 
     | 
    
         | 
| 
      
 144 
     | 
    
         
            +
                    @options[:at_tags] ||= false
         
     | 
| 
      
 145 
     | 
    
         
            +
                    opts.on('-@', '--at_tags', 'Highlight @tags and values in the document') do
         
     | 
| 
      
 146 
     | 
    
         
            +
                      @options[:at_tags] = true
         
     | 
| 
      
 147 
     | 
    
         
            +
                    end
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                    @options[:wiki_links] ||= false
         
     | 
| 
      
 150 
     | 
    
         
            +
                    opts.on('--[no-]wiki-links', 'Highlight [[wiki links]]') do |opt|
         
     | 
| 
      
 151 
     | 
    
         
            +
                      @options[:wiki_links] = opt
         
     | 
| 
      
 152 
     | 
    
         
            +
                    end
         
     | 
| 
      
 153 
     | 
    
         
            +
             
     | 
| 
       116 
154 
     | 
    
         
             
                    opts.on('-v', '--version', 'Display version number') do
         
     | 
| 
       117 
155 
     | 
    
         
             
                      puts version
         
     | 
| 
       118 
156 
     | 
    
         
             
                      exit
         
     | 
| 
         @@ -137,12 +175,13 @@ module CLIMarkdown 
     | 
|
| 
       137 
175 
     | 
    
         
             
                    exit 1
         
     | 
| 
       138 
176 
     | 
    
         
             
                  end
         
     | 
| 
       139 
177 
     | 
    
         | 
| 
       140 
     | 
    
         
            -
                   
     | 
| 
      
 178 
     | 
    
         
            +
                  if !File.exist?(config) || @options[:update_config]
         
     | 
| 
       141 
179 
     | 
    
         
             
                    FileUtils.mkdir_p(File.dirname(config))
         
     | 
| 
       142 
180 
     | 
    
         
             
                    File.open(config, 'w') do |f|
         
     | 
| 
       143 
181 
     | 
    
         
             
                      opts = @options.dup
         
     | 
| 
       144 
182 
     | 
    
         
             
                      opts.delete(:list)
         
     | 
| 
       145 
183 
     | 
    
         
             
                      opts.delete(:section)
         
     | 
| 
      
 184 
     | 
    
         
            +
                      opts.delete(:update_config)
         
     | 
| 
       146 
185 
     | 
    
         
             
                      f.puts YAML.dump(opts)
         
     | 
| 
       147 
186 
     | 
    
         
             
                      warn "Config file saved to #{config}"
         
     | 
| 
       148 
187 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -165,12 +204,13 @@ module CLIMarkdown 
     | 
|
| 
       165 
204 
     | 
    
         
             
                  renderer.options = @options
         
     | 
| 
       166 
205 
     | 
    
         | 
| 
       167 
206 
     | 
    
         
             
                  markdown = Redcarpet::Markdown.new(renderer,
         
     | 
| 
      
 207 
     | 
    
         
            +
                                                     no_intra_emphasis: !@options[:intra_emphasis],
         
     | 
| 
       168 
208 
     | 
    
         
             
                                                     autolink: true,
         
     | 
| 
       169 
209 
     | 
    
         
             
                                                     fenced_code_blocks: true,
         
     | 
| 
       170 
210 
     | 
    
         
             
                                                     footnotes: true,
         
     | 
| 
       171 
211 
     | 
    
         
             
                                                     hard_wrap: false,
         
     | 
| 
       172 
212 
     | 
    
         
             
                                                     highlight: true,
         
     | 
| 
       173 
     | 
    
         
            -
                                                     lax_spacing:  
     | 
| 
      
 213 
     | 
    
         
            +
                                                     lax_spacing: @options[:lax_spacing],
         
     | 
| 
       174 
214 
     | 
    
         
             
                                                     quote: false,
         
     | 
| 
       175 
215 
     | 
    
         
             
                                                     space_after_headers: false,
         
     | 
| 
       176 
216 
     | 
    
         
             
                                                     strikethrough: true,
         
     | 
| 
         @@ -189,6 +229,9 @@ module CLIMarkdown 
     | 
|
| 
       189 
229 
     | 
    
         
             
                      rescue StandardError
         
     | 
| 
       190 
230 
     | 
    
         
             
                        input = IO.read(file)
         
     | 
| 
       191 
231 
     | 
    
         
             
                      end
         
     | 
| 
      
 232 
     | 
    
         
            +
                      raise 'Nil input' if input.nil?
         
     | 
| 
      
 233 
     | 
    
         
            +
             
     | 
| 
      
 234 
     | 
    
         
            +
                      input.scrub!
         
     | 
| 
       192 
235 
     | 
    
         
             
                      input.gsub!(/\r?\n/, "\n")
         
     | 
| 
       193 
236 
     | 
    
         
             
                      if @options[:list]
         
     | 
| 
       194 
237 
     | 
    
         
             
                        puts list_headers(input)
         
     | 
| 
         @@ -200,11 +243,7 @@ module CLIMarkdown 
     | 
|
| 
       200 
243 
     | 
    
         
             
                    printout
         
     | 
| 
       201 
244 
     | 
    
         
             
                  elsif !$stdin.isatty
         
     | 
| 
       202 
245 
     | 
    
         
             
                    @file = nil
         
     | 
| 
       203 
     | 
    
         
            -
                     
     | 
| 
       204 
     | 
    
         
            -
                      input = $stdin.read.force_encoding('utf-8')
         
     | 
| 
       205 
     | 
    
         
            -
                    rescue StandardError
         
     | 
| 
       206 
     | 
    
         
            -
                      input = $stdin.read
         
     | 
| 
       207 
     | 
    
         
            -
                    end
         
     | 
| 
      
 246 
     | 
    
         
            +
                    input = $stdin.read.scrub
         
     | 
| 
       208 
247 
     | 
    
         
             
                    input.gsub!(/\r?\n/, "\n")
         
     | 
| 
       209 
248 
     | 
    
         
             
                    if @options[:list]
         
     | 
| 
       210 
249 
     | 
    
         
             
                      puts list_headers(input)
         
     | 
| 
         @@ -0,0 +1,77 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module CLIMarkdown
         
     | 
| 
      
 4 
     | 
    
         
            +
              module TaskPaper
         
     | 
| 
      
 5 
     | 
    
         
            +
                TASK_RX = /^(?<indent>(?:    |\t)*?)(?<marker>-)(?<task>\s+\S.*?)$/
         
     | 
| 
      
 6 
     | 
    
         
            +
                PROJECT_RX = /^(?<indent>(?:    |\t)*?)(?<project>[^- \t].*?:)(?<tags> @\S+)*$/
         
     | 
| 
      
 7 
     | 
    
         
            +
                NOTE_RX = /^(?<indent>(?:    |\t)+)(?<note>(?<!- ).*?(?!:))$/
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 10 
     | 
    
         
            +
                  include CLIMarkdown::Colors
         
     | 
| 
      
 11 
     | 
    
         
            +
                  attr_writer :theme
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  def color(key)
         
     | 
| 
      
 14 
     | 
    
         
            +
                    val = nil
         
     | 
| 
      
 15 
     | 
    
         
            +
                    keys = key.split(/[ ,>]/)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    if @theme.key?(keys[0])
         
     | 
| 
      
 17 
     | 
    
         
            +
                      val = @theme[keys.shift]
         
     | 
| 
      
 18 
     | 
    
         
            +
                    else
         
     | 
| 
      
 19 
     | 
    
         
            +
                      @log.error("Invalid theme key: #{key}") unless keys[0] =~ /^text/
         
     | 
| 
      
 20 
     | 
    
         
            +
                      return c([:reset])
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
                    keys.each do |k|
         
     | 
| 
      
 23 
     | 
    
         
            +
                      if val.key?(k)
         
     | 
| 
      
 24 
     | 
    
         
            +
                        val = val[k]
         
     | 
| 
      
 25 
     | 
    
         
            +
                      else
         
     | 
| 
      
 26 
     | 
    
         
            +
                        @log.error("Invalid theme key: #{k}")
         
     | 
| 
      
 27 
     | 
    
         
            +
                        return c([:reset])
         
     | 
| 
      
 28 
     | 
    
         
            +
                      end
         
     | 
| 
      
 29 
     | 
    
         
            +
                    end
         
     | 
| 
      
 30 
     | 
    
         
            +
                    if val.is_a? String
         
     | 
| 
      
 31 
     | 
    
         
            +
                      val = "x #{val}"
         
     | 
| 
      
 32 
     | 
    
         
            +
                      res = val.split(/ /).map(&:to_sym)
         
     | 
| 
      
 33 
     | 
    
         
            +
                      c(res)
         
     | 
| 
      
 34 
     | 
    
         
            +
                    else
         
     | 
| 
      
 35 
     | 
    
         
            +
                      c([:reset])
         
     | 
| 
      
 36 
     | 
    
         
            +
                    end
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                  def is_taskpaper?(input)
         
     | 
| 
      
 40 
     | 
    
         
            +
                    projects = input.split(PROJECT_RX)
         
     | 
| 
      
 41 
     | 
    
         
            +
                    tasks = 0
         
     | 
| 
      
 42 
     | 
    
         
            +
                    if projects.count > 1
         
     | 
| 
      
 43 
     | 
    
         
            +
                      projects.each do |proj|
         
     | 
| 
      
 44 
     | 
    
         
            +
                        tasks += proj.scan(TASK_RX).count
         
     | 
| 
      
 45 
     | 
    
         
            +
                      end
         
     | 
| 
      
 46 
     | 
    
         
            +
                    end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                    tasks >= 6
         
     | 
| 
      
 49 
     | 
    
         
            +
                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                  def highlight(input, theme)
         
     | 
| 
      
 52 
     | 
    
         
            +
                    @theme = theme
         
     | 
| 
      
 53 
     | 
    
         
            +
                    mc = color('taskpaper marker')
         
     | 
| 
      
 54 
     | 
    
         
            +
                    tc = color('taskpaper task')
         
     | 
| 
      
 55 
     | 
    
         
            +
                    pc = color('taskpaper project')
         
     | 
| 
      
 56 
     | 
    
         
            +
                    nc = color('taskpaper note')
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                    input.gsub!(PROJECT_RX) do
         
     | 
| 
      
 59 
     | 
    
         
            +
                      m = Regexp.last_match
         
     | 
| 
      
 60 
     | 
    
         
            +
                      "#{m['indent']}#{pc}#{m['project']}#{m['tags']}"
         
     | 
| 
      
 61 
     | 
    
         
            +
                    end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                    input.gsub!(TASK_RX) do
         
     | 
| 
      
 64 
     | 
    
         
            +
                      m = Regexp.last_match
         
     | 
| 
      
 65 
     | 
    
         
            +
                      "#{m['indent']}#{mc}- #{tc}#{m['task']}"
         
     | 
| 
      
 66 
     | 
    
         
            +
                    end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                    input.gsub!(NOTE_RX) do
         
     | 
| 
      
 69 
     | 
    
         
            +
                      m = Regexp.last_match
         
     | 
| 
      
 70 
     | 
    
         
            +
                      "#{m['indent']}#{nc}#{m['note']}"
         
     | 
| 
      
 71 
     | 
    
         
            +
                    end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                    input
         
     | 
| 
      
 74 
     | 
    
         
            +
                  end
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
              end
         
     | 
| 
      
 77 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/mdless/theme.rb
    CHANGED
    
    | 
         @@ -103,7 +103,17 @@ module CLIMarkdown 
     | 
|
| 
       103 
103 
     | 
    
         
             
                    'equation' => 'b blue'
         
     | 
| 
       104 
104 
     | 
    
         
             
                  },
         
     | 
| 
       105 
105 
     | 
    
         
             
                  'super' => 'b green',
         
     | 
| 
       106 
     | 
    
         
            -
                  'text' => 'white'
         
     | 
| 
      
 106 
     | 
    
         
            +
                  'text' => 'white',
         
     | 
| 
      
 107 
     | 
    
         
            +
                  'at_tags' => {
         
     | 
| 
      
 108 
     | 
    
         
            +
                    'tag' => 'magenta',
         
     | 
| 
      
 109 
     | 
    
         
            +
                    'value' => 'b white'
         
     | 
| 
      
 110 
     | 
    
         
            +
                  },
         
     | 
| 
      
 111 
     | 
    
         
            +
                  'taskpaper' => {
         
     | 
| 
      
 112 
     | 
    
         
            +
                    'marker' => 'b white',
         
     | 
| 
      
 113 
     | 
    
         
            +
                    'project' => 'b green',
         
     | 
| 
      
 114 
     | 
    
         
            +
                    'task' => 'white',
         
     | 
| 
      
 115 
     | 
    
         
            +
                    'note' => 'd white'
         
     | 
| 
      
 116 
     | 
    
         
            +
                  }
         
     | 
| 
       107 
117 
     | 
    
         
             
                }
         
     | 
| 
       108 
118 
     | 
    
         | 
| 
       109 
119 
     | 
    
         
             
                def load_theme_file(theme_file)
         
     | 
    
        data/lib/mdless/version.rb
    CHANGED
    
    
    
        data/lib/mdless.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: mdless
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.0.15
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Brett Terpstra
         
     | 
| 
         @@ -84,6 +84,7 @@ files: 
     | 
|
| 
       84 
84 
     | 
    
         
             
            - lib/mdless/hash.rb
         
     | 
| 
       85 
85 
     | 
    
         
             
            - lib/mdless/string.rb
         
     | 
| 
       86 
86 
     | 
    
         
             
            - lib/mdless/tables.rb
         
     | 
| 
      
 87 
     | 
    
         
            +
            - lib/mdless/taskpaper.rb
         
     | 
| 
       87 
88 
     | 
    
         
             
            - lib/mdless/theme.rb
         
     | 
| 
       88 
89 
     | 
    
         
             
            - lib/mdless/version.rb
         
     | 
| 
       89 
90 
     | 
    
         
             
            homepage: http://brettterpstra.com/project/mdless/
         
     | 
| 
         @@ -113,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       113 
114 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       114 
115 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       115 
116 
     | 
    
         
             
            requirements: []
         
     | 
| 
       116 
     | 
    
         
            -
            rubygems_version: 3.2. 
     | 
| 
      
 117 
     | 
    
         
            +
            rubygems_version: 3.2.16
         
     | 
| 
       117 
118 
     | 
    
         
             
            signing_key:
         
     | 
| 
       118 
119 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       119 
120 
     | 
    
         
             
            summary: A pager like less, but for Markdown files
         
     |