-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfendo.markup.common.fs
128 lines (98 loc) · 3.91 KB
/
fendo.markup.common.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
.( fendo.markup.common.fs ) cr
\ This file is part of Fendo
\ (http://programandala.net/en.program.fendo.html).
\ This file defines some common words for the markup definitions, also
\ required by the links module.
\ Last modified 20210429T1659+0200.
\ See change log at the end of the file.
\ Copyright (C) 2013,2014,2017 Marcos Cruz (programandala.net)
\ Fendo is free software; you can redistribute
\ it and/or modify it under the terms of the GNU General
\ Public License as published by the Free Software
\ Foundation; either version 2 of the License, or (at your
\ option) any later version.
\ Fendo is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied
\ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\ PURPOSE. See the GNU General Public License for more
\ details.
\ You should have received a copy of the GNU General Public
\ License along with this program; if not, see
\ <http://gnu.org/licenses>.
\ ==============================================================
\ Requirements {{{1
forth_definitions
\ require galope/s-comma.fs \ `s,`
require galope/unhtml.fs
fendo_definitions
\ ==============================================================
\ Parser vectors {{{1
\ Some words defined in <fendo.parser.fs> will be needed earlier.
defer content ( ca len -- )
\ Manage a string of content: print it and update the counters.
defer evaluate_content ( ca len -- )
\ Evaluate a string as page content.
\ defer close_pending ( -- ) \ XXX TMP
\ Close the pending markups.
\ ==============================================================
\ Common tools {{{1
: :echo_name ( ca len -- )
2dup :create s,
does> ( -- ) ( dfa ) count echo ;
\ Create a word that prints its own name.
\ ca len = word name
: :echo_name_ ( ca len -- )
2dup :create s,
does> ( -- ) ( dfa ) count echo separate? on ;
\ Create a word that prints its own name
\ and forces separation from the following text.
\ ca len = word name
: :echo_name+ ( ca len -- )
2dup :create s,
does> ( -- ) ( dfa ) count _echo separate? off ;
\ Create a word that prints its own name
\ and forces the following text will not be separated.
\ ca len = word name
variable header_cell?
\ flag, is it a header cell the latest opened cell in the table?
variable table_started?
\ flag, is a table open?
variable execute_markup?
\ flag, execute the markup while parsing?
execute_markup? on \ execute by default; otherwise print it
variable preserve_eol?
\ flag, preserve in the target the end of lines of the source?
variable forth_code_depth
\ depth level of the parsed Forth code block?
: (unmarkup) ( ca len -- ca' len' )
echo>string evaluate_content echoed $@ save-mem unhtml ;
\ Remove the markup of a string.
\ The method used is to convert it to HTML and then remove the HTML,
\ easier than removing all possible original markups.
\ Gforth's `save-mem` copies a memory block into a newly allocated
\ region in the heap. It is needed because the region used by `echoed`
\ will be restored at the end of `unmarkup`.
\
\ XXX TODO -- remove double spaces? (with galope/unspace.fs)
: unmarkup ( ca len -- ca' len' )
save_echo (unmarkup) restore_echo ;
\ Remove the markup of a string; the current status of `echo` is preserved.
.( fendo.markup.common.fs compiled) cr
\ ==============================================================
\ Change log {{{1
\ 2014-03-04: Start. Code extracted from <fendo.markup.fs>.
\
\ 2014-03-04: Change: `xhtml?` moved to <fendo.config.fs>.
\
\ 2014-03-04: Change: parser vectors moved here from
\ <fendo.markup.wiki.fs>.
\
\ 2014-11-08: New: `unmarkup` and `(unmarkup)`.
\
\ 2017-06-22: Update source style, layout and header.
\
\ 2018-12-08: Update notation of Forth words in comments and strings.
\
\ 2021-04-29: Require `s,`, word removed from Gforth between versions
\ 0.7.9_20201231 and 0.7.9_20210422, and added to Galope.
\ vim: filetype=gforth