madness 1.2.2 → 1.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b6927fd9ec118b3482a7bcd1d73dad2506ccbe032ea02452131cfeb1f1395fb
4
- data.tar.gz: bcb7fcbc8fd2a9bd9e58fa409f6893910901c3334b4f2311f256f36723299bac
3
+ metadata.gz: c5790a84273b260c95800d1497ce38a0d5e7f2eabe77b8231309ebf70eb7acb4
4
+ data.tar.gz: 013d8d7b8dd741bc5a03092c58c6326caa2cdf6c82b001be4755615e6184439b
5
5
  SHA512:
6
- metadata.gz: 0c2ba29929f8c38086a9687752134589a6af6ade4568f5ecc88b94ae1788c84ee9f1b8a1b26b15385337b7f2a1ee8fb167977e108d67a38419a678a45d0a2a81
7
- data.tar.gz: 4a5f45398511db07c9cc5ac5228690ee8e37d610fd13fac55c7bb5717d235f1850a65720ffb6ffb1cbbc7d1ca395ef28110714b76656367f98b1cb8e94b7ab17
6
+ metadata.gz: 942b0408a4ef4e85630703cd31a0c1b0c9d4a5695db685d612cd4280dc01282e725b63629b006dd41abf1ec198ac13df34370444820ea00bdf67c0ffe9c686b4
7
+ data.tar.gz: 1d0c07859780758c0ea6211ac6f0f62662f49be96adf2d083aba88703148b69e0979caeea5ca47351b5aa775310172533d74ccdb82566013fbd137172de22d9b
data/README.md CHANGED
@@ -2,12 +2,6 @@
2
2
 
3
3
  # Madness - Instant Markdown Server
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/madness.svg)](https://badge.fury.io/rb/madness)
6
- [![Build Status](https://github.com/DannyBen/madness/workflows/Test/badge.svg)](https://github.com/DannyBen/madness/actions?query=workflow%3ATest)
7
- [![Maintainability](https://api.codeclimate.com/v1/badges/fa440dc4dbf895734d74/maintainability)](https://codeclimate.com/github/DannyBen/madness/maintainability)
8
-
9
- ---
10
-
11
5
  Madness is a command line server for rendering markdown documents in your
12
6
  browser. It is designed to facilitate easy development of internal
13
7
  markdown-based documentation sites.
@@ -267,8 +261,32 @@ file or a directory in the same directory as the file itself.
267
261
 
268
262
  ### Mermaid Diagrams and Charts
269
263
 
270
- When the `mermaid` option is enabled, you may display any mermaid diagram in
271
- your document by enclosing it in a `<div class='mermaid'>...</div>` block.
264
+ When the `mermaid` option is enabled, you can embed Mermaid diagrams in your
265
+ document using either of the following methods:
266
+
267
+ 1. **Using a `<div>` block with `mermaid` class**:
268
+
269
+ ```html
270
+ <div class="mermaid">
271
+ graph TD;
272
+ A-->B;
273
+ A-->C;
274
+ B-->D;
275
+ C-->D;
276
+ </div>
277
+ ```
278
+
279
+ 2. **Using a code fence with `mermaid` language specifier**:
280
+
281
+ ````markdown
282
+ ```mermaid
283
+ graph TD;
284
+ A-->B;
285
+ A-->C;
286
+ B-->D;
287
+ C-->D;
288
+ ```
289
+ ````
272
290
 
273
291
  ### Table of Contents Generation
274
292
 
data/lib/madness/cli.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'mister_bin'
2
2
 
3
3
  module Madness
4
- # The CLI class is used by the bashly binary and forwards incoming CLI
5
- # commands to the relevant Bashly::Commands class
4
+ # The CLI class is used by the madness 'binary' and forwards incoming CLI
5
+ # commands to the relevant Madness::Commands class
6
6
  class CLI
7
7
  def self.runner
8
8
  runner = MisterBin::Runner.new version: Madness::VERSION,
@@ -3,9 +3,9 @@ module Madness
3
3
  class Config < Base
4
4
  summary 'Manage the madness configuration file'
5
5
 
6
- usage 'bashly config new'
7
- usage 'bashly config show'
8
- usage 'bashly config (-h|--help)'
6
+ usage 'madness config new'
7
+ usage 'madness config show'
8
+ usage 'madness config (-h|--help)'
9
9
 
10
10
  command 'new', 'Create a new .madness.yml configuration file'
11
11
  command 'show', 'Show all configuration options'
@@ -36,10 +36,8 @@ module Madness
36
36
  level = matches[:level].size - 2
37
37
 
38
38
  spacer = ' ' * level
39
- slug = text.to_slug
39
+ slug = text.to_slug config.renderer
40
40
 
41
- # pandoc removes leading numbers and dots from header slugs, we do the same
42
- slug = slug.remove(/^[\d\-]+/) if config.renderer == 'pandoc'
43
41
  "#{spacer}- [#{text}](##{slug})"
44
42
  end
45
43
 
@@ -11,8 +11,14 @@ module Madness
11
11
  Addressable::URI.escape self
12
12
  end
13
13
 
14
- def to_slug
15
- downcase.strip.gsub(/[^[:alnum:]]/, '-').squeeze('-').remove(/(^-|-$)/)
14
+ def to_slug(renderer = nil)
15
+ result = downcase.strip
16
+
17
+ if renderer == 'pandoc'
18
+ result.remove(/[^a-z0-9 ]/).tr(' ', '-')
19
+ else
20
+ result.gsub(/[^[:alnum:]]/, '-').squeeze('-').remove(/(^-|-$)/)
21
+ end
16
22
  end
17
23
 
18
24
  # This is here so we can have one place that defines how to convert
@@ -6,6 +6,7 @@ module Madness
6
6
  include ServerHelper
7
7
 
8
8
  def render(text)
9
+ text = process_mermaid_blocks text if config.mermaid
9
10
  PandocRuby.new(text, [{ from: :gfm, to: :html }], *options).convert
10
11
  end
11
12
 
@@ -14,6 +15,12 @@ module Madness
14
15
  def options
15
16
  @options ||= config.highlighter ? [] : :no_highlight
16
17
  end
18
+
19
+ def process_mermaid_blocks(text)
20
+ text.gsub(/```mermaid\s+(.+?)\s+```/m) do
21
+ "<div class='mermaid'>#{$1.strip}</div>"
22
+ end
23
+ end
17
24
  end
18
25
  end
19
26
  end
@@ -36,7 +36,11 @@ module Madness
36
36
  end
37
37
 
38
38
  def handler_class
39
- config.highlighter ? HighlightRenderer : ::Redcarpet::Render::HTML
39
+ if config.mermaid || config.highlighter
40
+ CustomRenderer
41
+ else
42
+ ::Redcarpet::Render::HTML
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -0,0 +1,18 @@
1
+ require 'redcarpet'
2
+ require 'rouge'
3
+ require 'rouge/plugins/redcarpet'
4
+
5
+ module Madness
6
+ # Renderer with syntax highlighting support
7
+ class CustomRenderer < Redcarpet::Render::HTML
8
+ include Rouge::Plugins::Redcarpet
9
+
10
+ def block_code(code, language)
11
+ if language == 'mermaid'
12
+ "<div class='mermaid'>#{code}</div>"
13
+ else
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module Madness
2
- VERSION = '1.2.2'
2
+ VERSION = '1.2.4'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madness
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-16 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: addressable
@@ -294,7 +294,7 @@ files:
294
294
  - lib/madness/rendering/handler.rb
295
295
  - lib/madness/rendering/pandoc.rb
296
296
  - lib/madness/rendering/redcarpet.rb
297
- - lib/madness/rendering/redcarpet_highlighter.rb
297
+ - lib/madness/rendering/redcarpet_custom.rb
298
298
  - lib/madness/search.rb
299
299
  - lib/madness/server.rb
300
300
  - lib/madness/server_base.rb
@@ -327,7 +327,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
327
327
  - !ruby/object:Gem::Version
328
328
  version: '0'
329
329
  requirements: []
330
- rubygems_version: 3.6.2
330
+ rubygems_version: 3.6.9
331
331
  specification_version: 4
332
332
  summary: Instant Markdown Server
333
333
  test_files: []
@@ -1,10 +0,0 @@
1
- require 'redcarpet'
2
- require 'rouge'
3
- require 'rouge/plugins/redcarpet'
4
-
5
- module Madness
6
- # Renderer with syntax highlighting support
7
- class HighlightRenderer < Redcarpet::Render::HTML
8
- include Rouge::Plugins::Redcarpet
9
- end
10
- end