phlex-markdown 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +4 -0
- data/Gemfile +1 -0
- data/README.md +47 -0
- data/lib/phlex/markdown.rb +23 -6
- metadata +8 -10
- data/lib/phlex/markdown/version.rb +0 -7
- data/sig/phlex.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e4546655748fea3f6ab3004ff7d67d12b95e461d7a29ad6f876fd7998ee0444
|
4
|
+
data.tar.gz: a3bbde5d84b3d9642df40079b7f3f2bc36489e6dbda19205e2fe674adce6335a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 390f03b1b399c1c62bb4d844dbb253539661fda7b39f6b2c08c514905d7fc18184292a1e09b0dbb89e80a2acfba8d141506076f2fa978ec05cc5e8967a530594
|
7
|
+
data.tar.gz: f8ca5719060e644e31e9be6ef9d37dbf5904f55d5a834d2dd3beaa30721adc5cb075557e28f40eef30ebb87d0def4bcda9b8f8bdd2e5aa27ce9cedc91f4f6d3b
|
data/.editorconfig
CHANGED
data/Gemfile
CHANGED
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
|
|
data/lib/phlex/markdown.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "phlex"
|
3
4
|
require "markly"
|
4
5
|
|
5
6
|
module Phlex
|
@@ -44,7 +45,13 @@ module Phlex
|
|
44
45
|
p { visit_children(node) }
|
45
46
|
end
|
46
47
|
in :link
|
47
|
-
a(href: node.url) { visit_children(node) }
|
48
|
+
a(href: node.url, title: node.title) { visit_children(node) }
|
49
|
+
in :image
|
50
|
+
img(
|
51
|
+
src: node.url,
|
52
|
+
alt: node.each.first.string_content,
|
53
|
+
title: node.title
|
54
|
+
)
|
48
55
|
in :emph
|
49
56
|
em { visit_children(node) }
|
50
57
|
in :strong
|
@@ -57,10 +64,16 @@ module Phlex
|
|
57
64
|
in :list_item
|
58
65
|
li { visit_children(node) }
|
59
66
|
in :code
|
60
|
-
|
67
|
+
inline_code do |**attributes|
|
68
|
+
code(**attributes) { text(node.string_content) }
|
69
|
+
end
|
61
70
|
in :code_block
|
62
|
-
code_block(node.string_content,
|
63
|
-
pre(**attributes)
|
71
|
+
code_block(node.string_content, node.fence_info) do |**attributes|
|
72
|
+
pre(**attributes) do
|
73
|
+
code(class: "language-#{node.fence_info}") do
|
74
|
+
text(node.string_content)
|
75
|
+
end
|
76
|
+
end
|
64
77
|
end
|
65
78
|
in :hrule
|
66
79
|
hr
|
@@ -69,8 +82,12 @@ module Phlex
|
|
69
82
|
end
|
70
83
|
end
|
71
84
|
|
72
|
-
def
|
73
|
-
yield
|
85
|
+
def inline_code(**attributes)
|
86
|
+
yield(**attributes)
|
87
|
+
end
|
88
|
+
|
89
|
+
def code_block(code, language, **attributes)
|
90
|
+
yield(**attributes)
|
74
91
|
end
|
75
92
|
|
76
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.
|
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-
|
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
|
@@ -53,8 +53,6 @@ files:
|
|
53
53
|
- README.md
|
54
54
|
- SECURITY.md
|
55
55
|
- lib/phlex/markdown.rb
|
56
|
-
- lib/phlex/markdown/version.rb
|
57
|
-
- sig/phlex.rbs
|
58
56
|
homepage: https://github.com/joeldrapper/phlex-markdown
|
59
57
|
licenses:
|
60
58
|
- MIT
|
data/sig/phlex.rbs
DELETED