raindown 0.5.0 → 0.5.1

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: ae1eb87d8271ddcfcc3fb956311e11229421188a33f5bd7e0af70cffd2f49719
4
- data.tar.gz: 380a98d835cfa9de899c5870828ba157e89aa0d3a4b8621a495f1a0ecd1e9bf6
3
+ metadata.gz: 9e35dfde9371c5f805bff304124c0abe22ca89254f14c5c70d2996e14d0dbb0f
4
+ data.tar.gz: 76774aa6b06fec8b50e0929b9ac86259511fb1ab9417ce48fcfa56afd20c90cf
5
5
  SHA512:
6
- metadata.gz: b3e74f64840850c572446865664e5368915df5065f09e9483d530d58392acb13f0e20ce872b9f8ee1930154af82d4c3baf8bf6fbd7c370399315e3b7a3a3b480
7
- data.tar.gz: '09a95ee90ef2568aff8c783ecee3b2ac06590f0a71f1bde6e14e99e7e8f5c6e05776ca6ff3c7dcce22fd55a56e456273ecb0de2475fceb0785a312a022cd48fa'
6
+ metadata.gz: 454c35bfd6c74cc2c125d8229ffe971cb178fb40f4d87affad0fc5d345301fd4d5a0e32a15852f05eb35231e0054b2a5b55ff2a4eb7253cc85aef17f4d17e178
7
+ data.tar.gz: 33b41ed491f7cc8238f3c3d99b2d72e2b0197dce29146dd14bdc704dd0ea6fa64788c97ed5d60bda60ef4602e9e6dedb2d22b02a1f8886a5c4592a522d96886e
@@ -30,7 +30,7 @@ module Raindown
30
30
  raise NotAnEndpoint, "#{directive.name} on line #{directive.line} isn't an endpoint" unless directive.endpoint?
31
31
 
32
32
  content = File.read(path, encoding: Encoding::UTF_8)
33
- rewritten = EndpointRunner.new(content:, bare: BareDirectives.file?(path), only: directive.line - 1).rewrite
33
+ rewritten = EndpointRunner.new(content:, bare: BareDirectives.enabled?(path:, content:), only: directive.line - 1).rewrite
34
34
  return false if rewritten == content
35
35
 
36
36
  File.write(path, rewritten)
@@ -5,7 +5,8 @@ require_relative 'front_matter'
5
5
 
6
6
  module Raindown
7
7
  # Raindown files (.rd/.raindown) can write a directive like <{ if: draft }> as a bare if: draft on its own line.
8
- # Markdown files opt in with the --bare flag. Nodes like toc: and files: are handled by NodeBlocks, before the rest.
8
+ # Markdown files opt in with "raindown: true" in their front matter, or with the --bare flag.
9
+ # Nodes like toc: and files: are handled by NodeBlocks, before the rest.
9
10
  #
10
11
  # Bare directives have no end tag. A bare block directive closes itself after the content it applies to,
11
12
  # so where a block needs to wrap more than that, write it with delimiters and an end tag instead:
@@ -24,8 +25,8 @@ module Raindown
24
25
 
25
26
  module_function
26
27
 
27
- def enabled?(path: nil, bare: false)
28
- bare || file?(path)
28
+ def enabled?(path: nil, content: nil, bare: false)
29
+ bare || file?(path) || front_matter?(content)
29
30
  end
30
31
 
31
32
  def file?(path)
@@ -34,6 +35,16 @@ module Raindown
34
35
  EXTENSIONS.include?(File.extname(path).downcase)
35
36
  end
36
37
 
38
+ # Whether the front matter has "raindown: true". Front matter that isn't valid YAML fails when the file renders,
39
+ # so here it only means no.
40
+ def front_matter?(content)
41
+ return false unless content&.start_with?('---')
42
+
43
+ FrontMatter.parse(content).first[:raindown] == true
44
+ rescue Psych::Exception
45
+ false
46
+ end
47
+
37
48
  # Wrap each bare directive in Antlers delimiters and close its block, leaving code and front matter as-is.
38
49
  def expand(content)
39
50
  lines = content.lines
@@ -32,8 +32,8 @@ module Raindown
32
32
  new(markdown:, bare:)
33
33
  end
34
34
 
35
- # Raindown files read bare directives. A project's own nodes are only directives once they're loaded,
36
- # like with Nodes.load(path), the same as when the file renders.
35
+ # Raindown files read bare directives, as do Markdown files with "raindown: true" front matter.
36
+ # A project's own nodes are only directives once they're loaded, like with Nodes.load(path), the same as when the file renders.
37
37
  def self.read(path)
38
38
  new(markdown: File.read(path, encoding: Encoding::UTF_8), bare: BareDirectives.file?(path))
39
39
  end
@@ -41,7 +41,7 @@ module Raindown
41
41
  def initialize(markdown:, bare: false)
42
42
  @markdown = markdown
43
43
  @lines = markdown.lines
44
- @bare = bare
44
+ @bare = bare || BareDirectives.front_matter?(markdown)
45
45
  end
46
46
 
47
47
  # The headings in the order they appear, with their source text, like "Notes for {name}" before it's rendered.
@@ -26,7 +26,7 @@ module Raindown
26
26
  FETCHED = /\A {0,3}<!-- raindown:fetched [^\n]*? -->[ \t]*$/
27
27
 
28
28
  def self.rewrite(content:, path: nil, bare: false, execute: false, **)
29
- new(content:, bare: BareDirectives.enabled?(path:, bare:), execute:).rewrite
29
+ new(content:, bare: BareDirectives.enabled?(path:, content:, bare:), execute:).rewrite
30
30
  end
31
31
 
32
32
  def initialize(content:, bare: false, execute: false, only: nil)
@@ -18,7 +18,7 @@ module Raindown
18
18
 
19
19
  def initialize(content:, path: nil, bare: false, metadata: NoMetadata)
20
20
  @content = content
21
- @bare = BareDirectives.enabled?(path:, bare:)
21
+ @bare = BareDirectives.enabled?(path:, content:, bare:)
22
22
  @metadata = metadata
23
23
  end
24
24
 
data/lib/raindown.rb CHANGED
@@ -47,6 +47,8 @@ module Raindown
47
47
  # Directives like "toc:" export to HTML as bold or comments depending on hide_directives config.
48
48
  # Code blocks are highlighted, unless highlight_code is false for a site that highlights code in the browser.
49
49
  def render(markdown:, metadata: NoMetadata, bare: false, hide_directives: false, highlight_code: true)
50
+ bare ||= BareDirectives.front_matter?(markdown)
51
+
50
52
  highlighting(highlight_code) do
51
53
  Fragments.collect do
52
54
  # Components' HTML goes back in, then their headings get unique ids, before nodes like the TOC see it.
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raindown
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raindown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi