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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9decdb08e89ad1d8deb79e6782b7961102150af4e6e20e0dff67a4ea7ff6c6d7
4
- data.tar.gz: 50e51626d52911b3ddb2f31404ede909bdea835b230dff35ed9d4592d6ea1cc9
3
+ metadata.gz: 3e4546655748fea3f6ab3004ff7d67d12b95e461d7a29ad6f876fd7998ee0444
4
+ data.tar.gz: a3bbde5d84b3d9642df40079b7f3f2bc36489e6dbda19205e2fe674adce6335a
5
5
  SHA512:
6
- metadata.gz: a09c726ac8e02922efd62342038ebe87abdb107c1729881d0998665d5a6b7147f41294140c6e26b5342a6c56c1b4cca4c9aaf1f399480a0d95caf947d12036da
7
- data.tar.gz: 1736bc45133d4336846c8accb29128e27ae9499550ebad59287624a99c2cd09d33b268c95999d670f22300f518e46788c4a8da6cd7a583066c14ccb7d6dcc84f
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/Gemfile CHANGED
@@ -5,6 +5,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
5
 
6
6
  gemspec
7
7
 
8
+ gem "phlex", github: "joeldrapper/phlex"
8
9
  gem "capybara"
9
10
  gem "rubocop"
10
11
  gem "solargraph"
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
 
@@ -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
- whitespace { code { text(node.string_content) } }
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, language: node.fence_info) do |**attributes|
63
- pre(**attributes) { text(node.string_content) }
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 code_block(code, language:)
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.1.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
@@ -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
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- class Markdown
5
- VERSION = "0.1.0"
6
- end
7
- end
data/sig/phlex.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Phlex
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end