mdless 2.0.23 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3eaea78c835d8fcd10e100f47897d6a35201abaaa553c01812ab392100175edb
4
- data.tar.gz: 82b99dfb00e22ff425dac9225b09ca6a373e92f6e328c849db5719c180002ee1
3
+ metadata.gz: cd020f19c756d65ae77a7776165c1aeadd0b2339a9dcabf82018f7e7a10105fc
4
+ data.tar.gz: 650881325a80cd06c61656f339a30d8e45f74b667842691c82e9a2b6b0ab3184
5
5
  SHA512:
6
- metadata.gz: 6f7848e8660d9b8c3383b17885a85be12b52cc42212444b316087b6d081666a883dfdf40bea21e4858c71cc7ef4ba51f5e9fecb63f52d853e740951cfaaf86bd
7
- data.tar.gz: 1622b095f616a0b36525712ffe2a44db665772fc2b5b1b3dced4eb3a53d689e335a5fd7008361b295b8a2183e7fc3dd6d8dc4aa468f7c3ea17e9550ed3d68209
6
+ metadata.gz: f41c118304004d8eb6f332b1edc66a51d6a4f346140acceb93db291bcade96635172f9e0c412119e60aad889ba6e4354e1491bf6ebf8d59b86770e408ff930fe
7
+ data.tar.gz: 5a9bdc6051825f50720a20a7767dbe759982a6b368f08b20905b703ffe7882d654aed737c919e445231bffefbb67328774856518546ba15e86667adf23c7b9c3
data/README.md CHANGED
@@ -62,11 +62,13 @@ The pager used is determined by system configuration in this order of preference
62
62
  -@, --at_tags Highlight @tags and values in the document
63
63
  -v, --version Display version number
64
64
  -w, --width=COLUMNS Column width to format for (default: terminal width)
65
+ --[no-]autolink Convert bare URLs and emails to <links>
65
66
  --[no-]inline_footnotes Display footnotes immediately after the paragraph that references them
66
67
  --[no-]intra-emphasis Parse emphasis inside of words (e.g. Mark_down_)
67
68
  --[no-]lax-spacing Allow lax spacing
68
69
  --links=FORMAT Link style ([inline, reference, paragraph], default inline,
69
70
  "paragraph" will position reference links after each paragraph)
71
+ --[no-]linebreaks Preserve line breaks
70
72
  --[no-]syntax Syntax highlight code blocks
71
73
  --taskpaper=OPTION Highlight TaskPaper format (true|false|auto)
72
74
  --update_config Update the configuration file with new keys and current command line options
@@ -76,6 +78,43 @@ The pager used is determined by system configuration in this order of preference
76
78
 
77
79
  The first time mdless is run, a config file will be written to `~/.config/mdless/config.yml`, based on the command line options used on the first run. Update that file to make any options permanent (config options will always be overridden by command line flags).
78
80
 
81
+ ```
82
+ ---
83
+ :at_tags: true
84
+ :autolink: true
85
+ :color: true
86
+ :inline_footnotes: true
87
+ :intra_emphasis: false
88
+ :lax_spacing: true
89
+ :links: :paragraph
90
+ :local_images: true
91
+ :pager: true
92
+ :preserve_linebreaks: false
93
+ :remote_images: false
94
+ :syntax_higlight: true
95
+ :taskpaper: :auto
96
+ :theme: default
97
+ :width: 120
98
+ :wiki_links: true
99
+ ```
100
+
101
+ - The `:at_tags` setting determines whether @tags will be highlighted. If this is enabled, colors will be pulled from the `at_tags` settings in the theme.
102
+ - `:autolink` will determine whether bare urls are turned into `<self-linking>` urls.
103
+ - `:color` will enable or disable all coloring.
104
+ - `:inline_footnotes` will determine the placement of footnotes. If true, footnotes will be added directly after the element that refers to them.
105
+ - `:intra_emphasis` will determine whether words containing underscores are rendered as italics or not.
106
+ - `:lax_spacing` determines whether a blank line is required around HTML elements.
107
+ - `:links` can be `inline`, `reference`, or `paragraph`. Paragraph puts reference links directly after the graf that refers to them.
108
+ - `:local_images` determines whether local images are processed using `chafa` or `imgcat` (whichever is available). `:remote_images` does the same for images referenced with web urls. If `:remote_images` is true, then `:local_images` is automatically enabled.
109
+ - `:pager` turns on or off pagination using `less` or closest available substitute.
110
+ - `:preserve_linebreaks` determines whether hard breaks within paragraphs are preserved. When converting to HTML, most Markdown processors will cause consecutive lines to be merged together, which is the default behavior for `mdless`. Turning this option on will cause lines to remain hard wrapped.
111
+ - `:syntax_highlight` will turn on/off syntax highlighting of code blocks (requires Pygments)
112
+ - `:taskpaper` determines whether a file is rendered as a TaskPaper document. This can be set to `:auto` to have TaskPaper detected from extension or content.
113
+ - `:theme` allows you to specify an alternate theme. See Customization below.
114
+ - `:width` allows you to permanantly set a width for wrapping of lines. If the width specified is greater than the available columns of the display, the display columns will be used instead.
115
+ - `:wiki_links` determines whether `[[wiki links]]` will be highlighted. If highlighted, colors are pulled from the `link` section of the theme.
116
+
117
+
79
118
  ## Customization
80
119
 
81
120
  On first run a default theme file will be placed in `~/.config/mdless/mdless.theme`. You can edit this file to modify the colors mdless uses when highlighting your files. You can copy this file and create multiple theme options which can be specified with the `-t NAME` option. For example, create `~/.config/mdless/brett.theme` and then call `mdless -t brett filename.md`.
@@ -139,4 +178,75 @@ To set a background color, use `on_[color]` with one of the 8 colors. This can b
139
178
 
140
179
  Use 'd' (dark) to indicate the darker version of a foreground color. On macOS (and possibly other systems) you can use the brighter version of a color by prefixing with "intense", e.g. `intense_red` or `on_intense_black`.
141
180
 
181
+ ## Integrations
182
+
183
+ ### Ranger
184
+
185
+ [Ranger](https://ranger.github.io) is a file manager that allows for quick navigation in the file hierarchy. A preview can be displayed for various file types. See docs at <https://github.com/ranger/ranger/wiki>.
186
+
187
+ mdless can be used in Ranger to preview Markdown and Taskpaper.
188
+
189
+ Ranger is installed with `brew install ranger`.
190
+
191
+ With `ranger --copy-config=scope` the configuration file for previews `scope.sh` is created in the directory `~/.config/ranger`.
192
+
193
+ The configuration file is already preconfigured. The following can be inserted above html to use mdless.
194
+
195
+ ```
196
+ ## Markdown
197
+ md|taskpaper)
198
+ mdless --taskpaper=auto -@ "${FILE_PATH}" && exit 5
199
+ ;;
200
+ ```
201
+
202
+ ### Gather
203
+
204
+ [Gather](https://brettterpstra.com/projects/gather-cli/) is a tool for converting web pages to Markdown. You can use it with mdless to create a Lynx-style web browser:
205
+
206
+ ```bash
207
+ $ gather https://brettterpstra.com/projects/gather-cli/ | mdless
208
+ ```
209
+
210
+ ### fzf
211
+
212
+ [fzf](https://github.com/junegunn/fzf) is a tool for selecting files and other menu options with typeahead fuzzy matching. You can set up `mdless` as a previewer when selecting Markdown or TaskPaper files.
213
+
214
+ ```
215
+ $ ls *.md | fzf --preview 'mdless --taskpaper auto --linebreaks {}'
216
+ ```
217
+
218
+ ### Fish
219
+
220
+ You can replace the cat command in Fish by creating the following functions in `~/.config/fish/functions`
221
+
222
+ `get_ext.fish`
223
+
224
+ ```fish
225
+ function get_ext -d 'Get the file extension from the argument'
226
+ set -l splits (string split "." $argv)
227
+ echo $splits[-1]
228
+ end
229
+ ```
230
+
231
+ `cat.fish`
232
+
233
+ ```fish
234
+ function cat -d "Use bat instead of cat unless it's a Markdown file, then use mdless"
235
+ set -l exts md markdown txt taskpaper
236
+
237
+ if not test -f $argv[-1]
238
+ echo "File not found: $argv"
239
+ return 0
240
+ end
241
+
242
+ if contains (get_ext $argv) $exts
243
+ mdless $argv
244
+ else
245
+ command bat --style plain --theme OneHalfDark $argv
246
+ end
247
+ end
248
+ ```
249
+
250
+ Note that if you do this, and you need uncolored output to pipe somewhere, you'll need to use `command cat FILE` to revert to the built-in `cat`. Otherwise your text will be full of the escape codes that `mdless` uses to colorize the output.
251
+
142
252
  <!--END README-->
@@ -232,7 +232,7 @@ module Redcarpet
232
232
  if MDLess.options[:preserve_linebreaks]
233
233
  "#{xc}#{text.gsub(/ +/, ' ').strip}#{xc}#{x}\n\n"
234
234
  else
235
- "#{xc}#{text.gsub(/ +/, ' ').gsub(/\n+/, ' ').strip}#{xc}#{x}\n\n"
235
+ "#{xc}#{text.gsub(/ +/, ' ').gsub(/\n+(?![:-])/, ' ').strip}#{xc}#{x}\n\n"
236
236
  end
237
237
  end
238
238
 
@@ -709,11 +709,12 @@ module Redcarpet
709
709
  def preprocess(input)
710
710
  input = color_meta(input)
711
711
 
712
+ replaced_input = input.clone
712
713
  ## Replace setex headers with ATX
713
- input.gsub!(/^([^\n]+)\n={2,}\s*$/m, "# \\1\n")
714
- input.gsub!(/^([^\n]+?)\n-{2,}\s*$/m, "## \\1\n")
714
+ replaced_input.gsub!(/^([^\n]+)\n={2,}\s*$/m, "# \\1\n")
715
+ replaced_input.gsub!(/^([^\n]+?)\n-{2,}\s*$/m, "## \\1\n")
715
716
 
716
- @headers = get_headers(input)
717
+ @headers = get_headers(replaced_input)
717
718
 
718
719
  if MDLess.options[:section]
719
720
  new_content = []
@@ -88,7 +88,7 @@ module CLIMarkdown
88
88
 
89
89
  default(:section, nil)
90
90
  opts.on('-s', '--section=NUMBER[,NUMBER]',
91
- 'Output only a headline-based section of the input (numeric from --list)') do |section|
91
+ 'Output only a headline-based section of the input (numeric from --list or text match)') do |section|
92
92
  sections = section.split(/ *, */).map(&:strip)
93
93
  MDLess.options[:section] = sections.map do |sect|
94
94
  if sect =~ /^\d+$/
@@ -126,6 +126,28 @@ module CLIMarkdown
126
126
  MDLess.options[:autolink] = p
127
127
  end
128
128
 
129
+ opts.on('--config', "Open the config file in #{ENV['EDITOR'] || 'default editor'}") do
130
+ raise 'No $EDITOR defined' unless ENV['EDITOR']
131
+
132
+ `#{ENV['EDITOR']} '#{File.expand_path('~/.config/mdless/config.yml')}'`
133
+ end
134
+
135
+ opts.on('--changes', 'Open the changelog to see recent updates') do
136
+ changelog = File.join(File.dirname(__FILE__), '..', '..', 'CHANGELOG.md')
137
+ system "mdless --linebreaks '#{changelog}'"
138
+ Process.exit 0
139
+ end
140
+
141
+ opts.on('--edit-theme', ["Open the default or specified theme file in #{ENV['EDITOR'] || 'default editor'}. ",
142
+ "If theme doesn't exist, a new theme file will be populated and opened."].join) do
143
+ raise 'No $EDITOR defined' unless ENV['EDITOR']
144
+
145
+ theme = MDLess.options[:theme] =~ /default/ ? 'mdless' : MDLess.options[:theme]
146
+ theme = File.expand_path("~/.config/mdless/#{theme}.theme")
147
+ File.open(theme, 'w') { |f| f.puts(YAML.dump(MDLess.theme)) } unless File.exist?(theme)
148
+ `#{ENV['EDITOR']} '#{theme}'`
149
+ end
150
+
129
151
  default(:inline_footnotes, false)
130
152
  opts.on('--[no-]inline_footnotes',
131
153
  'Display footnotes immediately after the paragraph that references them') do |p|
@@ -156,7 +178,7 @@ module CLIMarkdown
156
178
  end
157
179
  end
158
180
 
159
- default(:preserve_linebreaks, false)
181
+ default(:preserve_linebreaks, true)
160
182
  opts.on('--[no-]linebreaks', 'Preserve line breaks') do |opt|
161
183
  MDLess.options[:preserve_linebreaks] = opt
162
184
  end
data/lib/mdless/string.rb CHANGED
@@ -107,7 +107,7 @@ class ::String
107
107
  log = MDLess.log
108
108
  tag_color = color('at_tags tag')
109
109
  value_color = color('at_tags value')
110
- gsub(/(?<pre>\s|m)(?<tag>@[^ \].?!,("']+)(?:(?<lparen>\()(?<value>.*?)(?<rparen>\)))?/) do
110
+ gsub(/(?<pre>\s|m)(?<tag>@[^ \].?!,("'\n]+)(?:(?<lparen>\()(?<value>.*?)(?<rparen>\)))?/) do
111
111
  m = Regexp.last_match
112
112
  last_color = m.pre_match.last_color_code
113
113
  [
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CLIMarkdown
4
- VERSION = '2.0.23'
4
+ VERSION = '2.1.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdless
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.23
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-27 00:00:00.000000000 Z
11
+ date: 2023-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet