phlex-markdown 0.2.0 → 0.3.0

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: 70814edaf961f6b8b86c4918d06a92cb9d9d890dd7614dea761a03982b0ff8ce
4
- data.tar.gz: 5fc9e240f463805e88d718f5b1fe5ce2a9d099367cac196288b68657bd895505
3
+ metadata.gz: 3e4546655748fea3f6ab3004ff7d67d12b95e461d7a29ad6f876fd7998ee0444
4
+ data.tar.gz: a3bbde5d84b3d9642df40079b7f3f2bc36489e6dbda19205e2fe674adce6335a
5
5
  SHA512:
6
- metadata.gz: cf89b40b70e6d5fe0ed463e7756b6ba9f236eb95c1a23a6786e43df0f992bcf2d10f03c1dda23ec63f10058256e0c5704c35269a2bdd941a0f110fb3110cbdc5
7
- data.tar.gz: 56f39bdc50391a200f938a841637618d406eee64ea2d3e217dbc12b6636a4b0fe06d2bd58285de1cdf1980b35737be4528b5fc19113e18157c209136dfc21997
6
+ metadata.gz: 390f03b1b399c1c62bb4d844dbb253539661fda7b39f6b2c08c514905d7fc18184292a1e09b0dbb89e80a2acfba8d141506076f2fa978ec05cc5e8967a530594
7
+ data.tar.gz: f8ca5719060e644e31e9be6ef9d37dbf5904f55d5a834d2dd3beaa30721adc5cb075557e28f40eef30ebb87d0def4bcda9b8f8bdd2e5aa27ce9cedc91f4f6d3b
data/.editorconfig CHANGED
@@ -11,3 +11,7 @@ indent_size = 2
11
11
  [*.erb]
12
12
  indent_style = space
13
13
  indent_size = 2
14
+
15
+ [*.md]
16
+ indent_style = space
17
+ indent_size = 2
data/README.md CHANGED
@@ -1,5 +1,52 @@
1
1
  # `phlex-markdown`
2
2
 
3
+ `Phlex::Markdown` is a [Phlex](https://phlex.fun) view that renders Markdown into HTML using Phlex. You could use it directly — it takes a String of markdown and renders it to safe HTML.
4
+
5
+ Alternatively, you can define a sub-class and override various methods to customise the output.
6
+
7
+ For example, here we override `h1` and `ul`, adding some Tailwind classes to them.
8
+
9
+ ```ruby
10
+ class MyMarkdown < Phlex::Markdown
11
+ def h1 = super(class: "font-bold text-xl")
12
+ def ul = super(class: "ml-4 pt-2")
13
+ end
14
+ ```
15
+
16
+ When we render the view.
17
+
18
+ ```ruby
19
+ content = <<~MD
20
+ # Hello World
21
+
22
+ - A
23
+ - B
24
+ - C
25
+ MD
26
+
27
+ output = MyMarkdown.new(content).call
28
+ ```
29
+
30
+ The `output` will use the attributes from our methods.
31
+
32
+ ```html
33
+ <h1 class="font-bold text-xl">Hello World</h1>
34
+ <ul class="ml-4 pt-2">
35
+ <li>A</li>
36
+ <li>B</li>
37
+ <li>C</li>
38
+ </ul>
39
+ ```
40
+
41
+ You could also wrap the whole document in an `<article>` element by overriding `template`.
42
+
43
+ ```ruby
44
+ class MyMarkdownArticle < Phlex::Markdown
45
+ def template
46
+ article(class: "prose") { super }
47
+ end
48
+ end
49
+ ```
3
50
 
4
51
  ### Community 🙌
5
52
 
@@ -64,9 +64,11 @@ module Phlex
64
64
  in :list_item
65
65
  li { visit_children(node) }
66
66
  in :code
67
- code { text(node.string_content) }
67
+ inline_code do |**attributes|
68
+ code(**attributes) { text(node.string_content) }
69
+ end
68
70
  in :code_block
69
- code_block(node.string_content, language: node.fence_info) do |**attributes|
71
+ code_block(node.string_content, node.fence_info) do |**attributes|
70
72
  pre(**attributes) do
71
73
  code(class: "language-#{node.fence_info}") do
72
74
  text(node.string_content)
@@ -80,8 +82,12 @@ module Phlex
80
82
  end
81
83
  end
82
84
 
83
- def code_block(code, language:)
84
- yield
85
+ def inline_code(**attributes)
86
+ yield(**attributes)
87
+ end
88
+
89
+ def code_block(code, language, **attributes)
90
+ yield(**attributes)
85
91
  end
86
92
 
87
93
  def visit_children(node)
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-17 00:00:00.000000000 Z
11
+ date: 2022-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: markly
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: phlex
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '0.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '0.5'
41
41
  description: A Markdown view for Phlex
42
42
  email:
43
43
  - joel@drapper.me