mdphlex 0.1.1 → 0.2.0
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +108 -16
- data/examples/html_in_markdown.rb +10 -1
- data/examples/html_in_markdown_output.md +16 -0
- data/lib/mdphlex/md.rb +5 -0
- data/lib/mdphlex/version.rb +1 -1
- data/quickdraw/mdphlex.test.rb +18 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7df543d1ff68faf2b25ce38d74a767d5957a4322ce83d7ad424190cd7ee0bd7f
|
4
|
+
data.tar.gz: 427fecb092f11651e9f5d463fd544ed6d6bb4891bfdd7a338c0e5312a51d5f35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f895e699d4d037f6f3aaf8d33a6ff9e263fb24a1ee07d455fcdd7c8e3fff11b707ba85a17b7f053c33e78fe864dbaf18e8e67a97c62e520aafd3a747af68aef
|
7
|
+
data.tar.gz: dc0f27b7faadd20203f588733b14236b6b1cbdd47db87aae3ec299a767a58534d51a5e1a5088f9b10021ce83f81d41554112e0d67ac1fb94d73a0a4874ee6698
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
# MDPhlex
|
2
2
|
|
3
|
-
> Inversion of Markdown
|
4
|
-
|
5
3
|
MDPhlex is a Phlex component for rendering Markdown. No... not rendering markdown into HTML, rendering plain Markdown, programmatically.
|
6
4
|
|
7
|
-
MDPhlex is perfect for dynamically creating context for LLMs, generating an llms.txt file from real content, or
|
5
|
+
MDPhlex is perfect for dynamically creating context for LLMs, generating an llms.txt file from real content, or composing markdown out of componentized pieces.
|
8
6
|
|
9
7
|
## Installation
|
10
8
|
|
@@ -16,7 +14,7 @@ gem 'mdphlex'
|
|
16
14
|
|
17
15
|
## Creating LLM Prompts with MDPhlex
|
18
16
|
|
19
|
-
MDPhlex shines when creating structured prompts for LLMs. Here's a simple example using custom tags:
|
17
|
+
MDPhlex shines when creating structured prompts for LLMs allowing comments and organization without cluttering the prompt. Here's a simple example using custom tags:
|
20
18
|
|
21
19
|
~~~ruby
|
22
20
|
class LLMPrompt < MDPhlex::MD
|
@@ -32,17 +30,21 @@ class LLMPrompt < MDPhlex::MD
|
|
32
30
|
|
33
31
|
def view_template
|
34
32
|
system do
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
p "You are an AI assistant specialized in #{@task}."
|
34
|
+
|
35
|
+
h2 "Goal"
|
36
|
+
# we should define the goal more clearly.
|
37
|
+
p "Use the available tools to help the user."
|
38
38
|
|
39
|
-
|
39
|
+
# what about guardrails?
|
40
|
+
end
|
40
41
|
|
41
42
|
if @tools.any?
|
42
43
|
tools do
|
43
44
|
@tools.each do |tool_def|
|
44
45
|
tool name: tool_def[:name] do
|
45
46
|
plain tool_def[:description]
|
47
|
+
# need to add input schemas
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
@@ -67,8 +69,11 @@ This outputs clean, structured markdown perfect for LLMs:
|
|
67
69
|
~~~xml
|
68
70
|
<system>
|
69
71
|
You are an AI assistant specialized in Ruby code analysis.
|
70
|
-
Use the available tools to help users effectively.</system>
|
71
72
|
|
73
|
+
## Goal
|
74
|
+
Use the available tools to help the user.
|
75
|
+
|
76
|
+
</system>
|
72
77
|
<tools>
|
73
78
|
<tool name="analyze_code">
|
74
79
|
Analyze Ruby code for improvements</tool>
|
@@ -77,11 +82,96 @@ Explain Ruby concepts and patterns</tool>
|
|
77
82
|
</tools>
|
78
83
|
~~~
|
79
84
|
|
80
|
-
The XML-style tags help LLMs understand different sections of the prompt, while Ruby's dynamic nature lets you generate prompts based on runtime conditions.
|
81
|
-
|
82
85
|
## Traditional Markdown Generation
|
83
86
|
|
84
|
-
MDPhlex also works great for generating regular Markdown content
|
87
|
+
MDPhlex also works great for generating regular Markdown content.
|
88
|
+
|
89
|
+
### Rails Integration with Markdown Rendering
|
90
|
+
|
91
|
+
With Rails 8.1's native markdown support, MDPhlex components integrate seamlessly:
|
92
|
+
|
93
|
+
~~~ruby
|
94
|
+
# app/components/page_component.rb
|
95
|
+
class PageComponent < MDPhlex::MD
|
96
|
+
def initialize(page)
|
97
|
+
@page = page
|
98
|
+
end
|
99
|
+
|
100
|
+
def view_template
|
101
|
+
h1 @page.title
|
102
|
+
|
103
|
+
p do
|
104
|
+
em "Last updated: #{@page.updated_at.strftime('%B %d, %Y')}"
|
105
|
+
end
|
106
|
+
|
107
|
+
hr
|
108
|
+
|
109
|
+
# Render page sections with proper markdown structure
|
110
|
+
@page.sections.each do |section|
|
111
|
+
h2 section.heading
|
112
|
+
|
113
|
+
p section.content
|
114
|
+
|
115
|
+
if section.code_example?
|
116
|
+
pre(language: section.language) { plain section.code }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
if @page.references.any?
|
121
|
+
h2 "References"
|
122
|
+
ul do
|
123
|
+
@page.references.each do |ref|
|
124
|
+
li do
|
125
|
+
a(href: ref.url) { ref.title }
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# app/controllers/pages_controller.rb
|
134
|
+
class PagesController < ApplicationController
|
135
|
+
def show
|
136
|
+
@page = Page.find(params[:id])
|
137
|
+
|
138
|
+
respond_to do |format|
|
139
|
+
format.html
|
140
|
+
format.md { render markdown: PageComponent.new(@page) }
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
~~~
|
145
|
+
|
146
|
+
When someone visits `/pages/123.md`, Rails will render:
|
147
|
+
|
148
|
+
~~~markdown
|
149
|
+
# Getting Started with Ruby
|
150
|
+
|
151
|
+
*Last updated: September 12, 2025*
|
152
|
+
|
153
|
+
---
|
154
|
+
|
155
|
+
## Introduction
|
156
|
+
|
157
|
+
Ruby is a dynamic, object-oriented programming language...
|
158
|
+
|
159
|
+
## Basic Syntax
|
160
|
+
|
161
|
+
Here's how to define a method in Ruby:
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
def greet(name)
|
165
|
+
puts "Hello, #{name}!"
|
166
|
+
end
|
167
|
+
```
|
168
|
+
|
169
|
+
## References
|
170
|
+
- [Official Ruby Documentation](https://ruby-doc.org)
|
171
|
+
- [Ruby Style Guide](https://rubystyle.guide)
|
172
|
+
~~~
|
173
|
+
|
174
|
+
### Dynamic Content Generation
|
85
175
|
|
86
176
|
~~~ruby
|
87
177
|
class ArticleContent < MDPhlex::MD
|
@@ -142,9 +232,9 @@ age = 30
|
|
142
232
|
Learn more in the [documentation](https://docs.example.com).
|
143
233
|
~~~
|
144
234
|
|
145
|
-
## Rendering MDPhlex inside Phlex::HTML
|
235
|
+
## Rendering MDPhlex inside Phlex::HTML (and vice versa)
|
146
236
|
|
147
|
-
MDPhlex components
|
237
|
+
MDPhlex components are Phlex compatible. Integrate them into any Phlex::HTML views or show HTML or other wcomented in Markdown:
|
148
238
|
|
149
239
|
~~~ruby
|
150
240
|
class ArticlePage < Phlex::HTML
|
@@ -191,9 +281,11 @@ end
|
|
191
281
|
|
192
282
|
## Why MDPhlex?
|
193
283
|
|
194
|
-
|
284
|
+
*But markdown is just text!?* Yes, but have you ever tried to render clean markdown from a lot of conditional logic? MDPhlex tames the mess with a simple and familiar API.
|
285
|
+
|
286
|
+
- **Component-based**: Build reusable Markdown with simple ruby classes
|
195
287
|
- **Dynamic Markdown**: Generate markdown from dynamic data
|
196
|
-
- **Composable**: Mix Phlex
|
288
|
+
- **Composable**: Mix Phlex and MDPhlex components freely
|
197
289
|
|
198
290
|
## License
|
199
291
|
|
@@ -37,5 +37,14 @@ class HTMLInMarkdownExample < MDPhlex::MD
|
|
37
37
|
end
|
38
38
|
|
39
39
|
if __FILE__ == $0
|
40
|
-
|
40
|
+
output = HTMLInMarkdownExample.new.call
|
41
|
+
puts output
|
42
|
+
|
43
|
+
File.write(
|
44
|
+
File.join(File.dirname(__FILE__), "html_in_markdown_output.md"),
|
45
|
+
output
|
46
|
+
)
|
47
|
+
|
48
|
+
puts "\n---"
|
49
|
+
puts "Output saved to examples/html_in_markdown_output.md"
|
41
50
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# HTML in Markdown
|
2
|
+
Markdown allows inline HTML like <strong>this bold text</strong> and <em>this italic text</em>.
|
3
|
+
|
4
|
+
You can use HTML entities directly: © & <div>
|
5
|
+
|
6
|
+
## Complex HTML
|
7
|
+
You can even include complex HTML structures:
|
8
|
+
<div class="alert" style="border: 1px solid red;">
|
9
|
+
<h3>Warning!</h3>
|
10
|
+
<p>This is an alert box created with HTML.</p>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
|
14
|
+
## Mixing Markdown and HTML
|
15
|
+
You can mix **Markdown formatting** with <code>HTML tags</code> seamlessly.
|
16
|
+
|
data/lib/mdphlex/md.rb
CHANGED
data/lib/mdphlex/version.rb
CHANGED
data/quickdraw/mdphlex.test.rb
CHANGED
@@ -421,3 +421,21 @@ test "multiple register_block_elements" do
|
|
421
421
|
</aside>
|
422
422
|
MD
|
423
423
|
end
|
424
|
+
|
425
|
+
test "to_markdown works" do
|
426
|
+
example = Class.new(MDPhlex::MD) do
|
427
|
+
register_block_element :note
|
428
|
+
|
429
|
+
def view_template
|
430
|
+
note(type: "info") do
|
431
|
+
h3 "This is a note."
|
432
|
+
end
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
assert_equal example.new.to_markdown, <<~MD
|
437
|
+
<note type="info">
|
438
|
+
### This is a note.
|
439
|
+
</note>
|
440
|
+
MD
|
441
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdphlex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Emde
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- examples/custom_elements.rb
|
53
53
|
- examples/custom_elements_output.md
|
54
54
|
- examples/html_in_markdown.rb
|
55
|
+
- examples/html_in_markdown_output.md
|
55
56
|
- examples/llm_prompt.rb
|
56
57
|
- examples/llm_prompt_output.md
|
57
58
|
- lib/mdphlex.rb
|