Skip to content

Commit 65b0271

Browse files
committed
v0.6.7 : add support for markdown
1 parent 88bac2e commit 65b0271

File tree

11 files changed

+202
-120
lines changed

11 files changed

+202
-120
lines changed

Cargo.lock

Lines changed: 66 additions & 106 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlpage"
3-
version = "0.6.6"
3+
version = "0.6.7"
44
edition = "2021"
55
description = "A SQL-only web application framework. Takes .sql files and formats the query result using pre-made configurable professional-looking components."
66
keywords = ["web", "sql", "framework"]
@@ -39,6 +39,7 @@ async-trait = "0.1.61"
3939
async-recursion = "1.0.0"
4040
include_dir = "0.7.2"
4141
config = { version = "0.13.3", features = ["json"] }
42+
markdown = { version = "1.0.0-alpha.9", features = ["log"] }
4243

4344
[build-dependencies]
44-
ureq = "2.6.2"
45+
ureq = "2.6.2"

examples/official-site/sqlpage/migrations/01_documentation.sql

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
2929
-- item level
3030
('title', 'Name of the list item, displayed prominently.', 'TEXT', FALSE, FALSE),
3131
('description', 'A description of the list item, displayed as greyed-out text.', 'TEXT', FALSE, TRUE),
32+
('description_md', 'A description of the list item, displayed as greyed-out text, in Markdown format, allowing you to use rich text formatting, including **bold** and *italic* text.', 'TEXT', FALSE, TRUE),
3233
('link', 'An URL to which the user should be taken when they click on the list item.', 'URL', FALSE, TRUE),
3334
('icon', 'An icon name (from tabler-icons.io) to display on the left side of the item.', 'TEXT', FALSE, TRUE),
3435
('color', 'The name of a color, to be displayed as a dot near the list item contents.', 'TEXT', FALSE, TRUE),
@@ -37,6 +38,11 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
3738

3839
INSERT INTO example(component, description, properties) VALUES
3940
('list', 'The most basic list', json('[{"component":"list"},{"title":"A"},{"title":"B"},{"title":"C"}]')),
41+
('list', 'A list with rich text descriptions', json('[{"component":"list"},
42+
{"title":"SQLPage", "description_md":"A **SQL**-based **page** generator for **PostgreSQL**, **MySQL**, and **SQLite**. [Free on Github](https://github.com/lovasoa/sqlpage)"},
43+
{"title":"Tabler", "description_md":"A **free** and **open-source** **HTML** template pack based on **Bootstrap**."},
44+
{"title":"Tabler Icons", "description_md":"A set of over **700** free MIT-licensed high-quality **SVG** icons for you to use in your web projects."}
45+
]')),
4046
('list', 'A beautiful list with bells and whistles.',
4147
json('[{"component":"list", "title":"Popular websites"}, '||
4248
'{"title":"Google", "link":"https://google.com", "description": "A search engine", "color": "red", "icon":"brand-google", "active": true}, '||
@@ -52,8 +58,15 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
5258
('columns', 'The number of columns in the grid of cards. This is just a hint, the grid will adjust dynamically to the user''s screen size, rendering fewer columns if needed to fit the contents.', 'INTEGER', TRUE, TRUE),
5359
-- item level
5460
('title', 'Name of the card, displayed at the top.', 'TEXT', FALSE, FALSE),
55-
('description', 'The body of the card.', 'TEXT', FALSE, TRUE),
61+
('description', 'The body of the card, where you put the main text contents of the card.
62+
This does not support rich text formatting, only plain text.
63+
If you want to use rich text formatting, use the `description_md` property instead.', 'TEXT', FALSE, TRUE),
64+
('description_md', '
65+
The body of the card, in Markdown format.
66+
This is useful if you want to display a lot of text in the card, with many options for formatting, such as
67+
line breaks, **bold**, *italics*, lists, #titles, [links](target.sql), ![images](photo.jpg), etc.', 'TEXT', FALSE, TRUE),
5668
('footer', 'Muted text to display at the bottom of the card.', 'TEXT', FALSE, TRUE),
69+
('footer_md', 'Muted text to display at the bottom of the card, with rich text formatting in Markdown format.', 'TEXT', FALSE, TRUE),
5770
('link', 'An URL to which the user should be taken when they click on the card.', 'URL', FALSE, TRUE),
5871
('icon', 'An icon name (from tabler-icons.io) to display on the left side of the card.', 'TEXT', FALSE, TRUE),
5972
('color', 'The name of a color, to be displayed on the left of the card to highlight it.', 'TEXT', FALSE, TRUE),
@@ -62,6 +75,10 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
6275

6376
INSERT INTO example(component, description, properties) VALUES
6477
('card', 'The most basic card', json('[{"component":"card"},{"title":"A"},{"title":"B"},{"title":"C"}]')),
78+
('card', 'A card with a Markdown description',
79+
json('[{"component":"card"}, {"title":"A card with a Markdown description", "description_md": "This is a card with a **Markdown** description. \n\n'||
80+
'This is useful if you want to display a lot of text in the card, with many options for formatting, such as '||
81+
'\n - **bold**, \n - *italics*, \n - [links](index.sql), \n - etc."}]')),
6582
('card', 'A beautiful card grid with bells and whistles.',
6683
json('[{"component":"card", "title":"Popular websites", "columns": 2}, '||
6784
'{"title":"Google", "link":"https://google.com", "description": "A search engine", "color": "red", "icon":"brand-google", "footer": "Owned by Alphabet Inc."}, '||
@@ -130,6 +147,8 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
130147
('center', 'Whether to center the title.', 'BOOLEAN', TRUE, TRUE),
131148
('width', 'How wide the paragraph should be, in characters.', 'INTEGER', TRUE, TRUE),
132149
('html', 'Raw html code to include on the page. Don''t use that if you are not sure what you are doing, it may have security implications.', 'TEXT', TRUE, TRUE),
150+
('contents', 'A top-level paragraph of text to display, without any formatting, without having to make additional queries.', 'TEXT', TRUE, TRUE),
151+
('contents_md', 'Rich text in the markdown format. Among others, this allows you to write bold text using **bold**, italics using *italics*, and links using [text](https://example.com).', 'TEXT', TRUE, TRUE),
133152
-- item level
134153
('contents', 'A span of text to display', 'TEXT', FALSE, FALSE),
135154
('link', 'An URL to which the user should be taken when they click on this span of text.', 'URL', FALSE, TRUE),
@@ -144,6 +163,39 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
144163

145164
INSERT INTO example(component, description, properties) VALUES
146165
('text', 'Rendering a simple text paragraph.', json('[{"component":"text", "contents":"Hello, world ! <3"}]')),
166+
('text', 'Rendering rich text using markdown', json('[{"component":"text", "contents_md":"\n'||
167+
'# Markdown in SQLPage\n\n' ||
168+
'## Simple formatting\n\n' ||
169+
'SQLPage supports only plain text as column values, but markdown allows easily adding **bold**, *italics*, and [links](index.sql).\n\n' ||
170+
'## Lists\n' ||
171+
'### Unordered lists\n' ||
172+
'* SQLPage is easy\n' ||
173+
'* SQLPage is fun\n' ||
174+
'* SQLPage is free\n\n' ||
175+
'### Ordered lists\n' ||
176+
'1. SQLPage is fast\n' ||
177+
'2. SQLPage is safe\n' ||
178+
'3. SQLPage is open-source\n\n' ||
179+
'## Code\n' ||
180+
'```sql\n' ||
181+
'SELECT ''list'' AS component;\n' ||
182+
'SELECT name as title FROM users;\n' ||
183+
'```\n\n' ||
184+
'## Tables\n\n' ||
185+
'| SQLPage component | Description | Documentation link |\n' ||
186+
'| --- | --- | --- |\n' ||
187+
'| text | A paragraph of text. | [Documentation](https://sql.ophir.dev/documentation.sql?component=text) |\n' ||
188+
'| list | A list of items. | [Documentation](https://sql.ophir.dev/documentation.sql?component=list) |\n' ||
189+
'| steps | A progress indicator. | [Documentation](https://sql.ophir.dev/documentation.sql?component=steps) |\n' ||
190+
'| form | A series of input fields. | [Documentation](https://sql.ophir.dev/documentation.sql?component=form) |\n\n' ||
191+
'## Quotes\n' ||
192+
'> Fantastic.\n>\n' ||
193+
'> — [HackerNews User](https://news.ycombinator.com/item?id=36194473#36209061) about SQLPage\n\n' ||
194+
'## Images\n' ||
195+
'![SQLPage logo](https://sql.ophir.dev/favicon.ico)\n\n' ||
196+
'## Horizontal rules\n' ||
197+
'---\n\n' ||
198+
'"}]')),
147199
('text', 'Rendering a paragraph with links and styling.',
148200
json('[{"component":"text", "title":"About SQL"}, '||
149201
'{"contents":"SQL", "bold":true, "italics": true}, '||

examples/official-site/sqlpage/migrations/02_hero_component.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ VALUES (
9393
'[{
9494
"component":"hero",
9595
"title": "SQLPage",
96-
"description": "Documentation for the SQLPage low-code web application framework.",
96+
"description_md": "Documentation for the *SQLPage* low-code web application framework.",
9797
"image": "https://upload.wikimedia.org/wikipedia/commons/e/e4/Lac_de_Zoug.jpg",
9898
"link": "/documentation.sql",
99-
"link_text": "Read Now!"
100-
},' || '{"title": "Fast", "description": "Pages load instantly, even on slow mobile networks.", "icon": "car", "color": "red", "link": "/"},' || '{"title": "Beautiful", "description": "Uses pre-defined components that look professional.", "icon": "eye", "color": "green", "link": "/"},' || '{"title": "Easy", "description": "You can teach yourself enough SQL to use SQLPage in a weekend.", "icon": "sofa", "color": "blue", "link": "/"}' || ']'
99+
"link_text": "Read Now!"},' ||
100+
'{"title": "Fast", "description": "Pages load instantly, even on slow mobile networks.", "icon": "car", "color": "red", "link": "/"},' ||
101+
'{"title": "Beautiful", "description": "Uses pre-defined components that look professional.", "icon": "eye", "color": "green", "link": "/"},' ||
102+
'{"title": "Easy", "description_md": "You can teach yourself enough SQL to use [**SQLPage**](https://sql.ophir.dev) in a weekend.", "icon": "sofa", "color": "blue", "link": "/"}' || ']'
101103
)
102104
);

examples/official-site/sqlpage/migrations/03_alert_component.sql

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ VALUES (
4545
TRUE,
4646
TRUE
4747
),
48+
(
49+
'alert',
50+
'description_md',
51+
'Detailed description or content of the alert message, in Markdown format, allowing you to use rich text formatting, including **bold** and *italic* text.',
52+
'TEXT',
53+
TRUE,
54+
TRUE
55+
),
4856
(
4957
'alert',
5058
'dismissible',
@@ -100,8 +108,7 @@ VALUES (
100108
'TEXT',
101109
FALSE,
102110
TRUE
103-
)
104-
;
111+
);
105112
-- Insert example(s) for the component
106113
INSERT INTO example(component, description, properties)
107114
VALUES (
@@ -164,4 +171,18 @@ VALUES (
164171
"link_text":"See source code"
165172
}]'
166173
)
174+
),
175+
(
176+
'alert',
177+
'An alert message with a Markdown-formatted description',
178+
JSON(
179+
'[
180+
{
181+
"component":"alert",
182+
"title":"Free and open source",
183+
"icon": "free-rights",
184+
"color": "info",
185+
"description_md":"*SQLPage* is entirely free and open source. You can **contribute** to it on [GitHub](https://github.com/lovasoa/SQLPage)."
186+
}]'
187+
)
167188
);

sqlpage/templates/alert.handlebars

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414

1515
<div>
1616
{{#if title}}<h4 class="alert-title" {{#if important}}style="color:inherit"{{/if}}>{{title}}</h4>{{/if}}
17-
{{#if description}}<div class="alert-description">{{description}}</div>{{/if}}
17+
{{~#if description~}}
18+
<div class="alert-description">
19+
{{~description~}}
20+
</div>
21+
{{~/if~}}
22+
{{~#if description_md~}}
23+
<div class="alert-description">
24+
{{{~markdown description_md~}}}
25+
</div>
26+
{{~/if~}}
1827
{{#if link}}
1928
<a href="{{link}}"
2029
class="btn btn-sm alert-link mt-2 px-2 {{#if important}}text-{{default color 'info'}}{{/if}}"

sqlpage/templates/card.handlebars

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,20 @@
2323
{{/if}}
2424
<div class="card-body">
2525
<h2 class="card-title fs-3">{{title}}</h2>
26-
<p class="text-muted">{{description}}</p>
26+
<div class="text-muted">
27+
{{~description~}}
28+
{{~#if description_md~}}
29+
{{{markdown description_md}}}
30+
{{~/if~}}
31+
</div>
2732
</div>
2833
{{#if footer}}
29-
<div class="card-footer py-2">{{footer}}</div>
34+
<div class="card-footer py-2">
35+
{{footer}}
36+
{{~#if footer_md~}}
37+
{{{markdown footer_md}}}
38+
{{~/if~}}
39+
</div>
3040
{{/if}}
3141
{{#if icon}}
3242
<div class="ribbon bg-{{color}} fs-2">

sqlpage/templates/hero.handlebars

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<header class="row align-items-center">
22
<div class="hero-title col text-center">
33
<h1 class="lh-lg" style="font-size: 3rem">{{title}}</h1>
4-
<p class="fs-1 mx-5 text-muted">{{description}}</p>
4+
<div class="fs-1 mx-5 text-muted">
5+
{{~description~}}
6+
{{~#if description_md~}}
7+
{{{markdown description_md}}}
8+
{{~/if~}}
9+
</div>
510
{{#if link}}
611
<a href="{{link}}" class="btn btn-primary mb-3">{{default link_text "Go"}}</a>
712
{{/if}}
@@ -32,7 +37,12 @@
3237
</a>
3338
{{/if}}
3439
</h2>
35-
<p class="mb-0">{{description}}</p>
40+
<div class="mb-0">
41+
{{~description~}}
42+
{{~#if description_md~}}
43+
{{{markdown description_md}}}
44+
{{~/if~}}
45+
</div>
3646
</div>
3747
</div>
3848
</div>

sqlpage/templates/list.handlebars

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
{{/if}}
2020
<div class="col text-truncate">
2121
{{title}}
22-
<div class="d-block text-muted text-truncate mt-n1">{{description}}</div>
22+
<div class="d-block text-muted text-truncate mt-n1">
23+
{{~description~}}
24+
{{~#if description_md~}}
25+
<div style="margin-bottom: -1rem">{{{markdown description_md}}}</div>
26+
{{~/if~}}
27+
</div>
2328
</div>
2429
</div>
2530
</{{#if link}}a {{else}}div{{/if}}>

sqlpage/templates/text.handlebars

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
{{#if title}}
33
<h1 id="{{id}}" class="mt-3 {{#if center}}text-center{{/if}}">{{title}}</h1>
44
{{/if}}
5+
{{#if contents_md}}
6+
{{{markdown contents_md}}}
7+
{{/if}}
58
<p class="{{#if center}}mx-auto{{/if}}" {{#if (not title)}}id="{{id}}"{{/if}}>
69
{{contents}}
710
{{~#each_row~}}
@@ -20,5 +23,8 @@
2023
{{~#if size}}fs-{{minus 7 size}} {{/if~}}
2124
">{{contents}}</span>
2225
{{~flush_delayed~}}
26+
{{~#if contents_md~}}
27+
{{{markdown contents_md}}}
28+
{{~/if~}}
2329
{{~/each_row~}}
2430
</p>

0 commit comments

Comments
 (0)