File: emphasis.lsed

package info (click to toggle)
stx2any 1.56-2.3
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 748 kB
  • sloc: sh: 312; python: 288; lisp: 137; makefile: 126; sed: 1
file content (83 lines) | stat: -rw-r--r-- 2,188 bytes parent folder | download | duplicates (4)
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
w_doc_id(s2aimpl.emph)dnl

This file is copyright (c) 2004,2005,2006 by Panu Kalliokoski
and released under the license in ../LICENSE

Different emphasis-like constructs.  These must not cross paragraph
boundaries and are only recognised in the presence of both an opening
and closing marker, so we handle them one paragraph at a time.

Literal blocks should be passed untouched.  If a literal block was met
when gathering a paragraph's lines (see below), it is processed now.
{{{
x
/^{{{$/ {
G
x
s#.*##
}
x
/^{{{$/,/^}}}$/ b
/^{{{\n/,/^}}}$/ b
}}}

First, gather lines until we reach an empty line or literal block to
process emphasis as paragraphs.  End of file has to be made a special
case.
{{{
: gather
s#
$##
$ b nogather
N
/\n$/ b nogather
/\n{{{$/ {
s###
x
s#.*#{{{#
x
b nogather
}
b gather
: nogather
}}}

Normalise whitespace.  Spaces inserted at the beginning and end of line
are taken away later.
{{{
s#^# #
s#$# #
}}}

Literal formatting.  We previously supported non-quoted versions but the
new quote-protection scheme should avoid them altogether.  This is quite
a regexp because it's complicated to say, in regular expressions, "a
span of text not containing the string /X/" (where len(/X/) w_gt 1).
{{{
s#\([ \n([{<"-]\)`'w_apo`'`'w_apo`'\([^ `]\(\([^`]\(`'w_apo`'[^`]\)*\(`'w_us`'\)*\(`'w[^_]\)*\(`'[^w]\)*\)*[^ `]\)*\)`'w_apo`'`'w_apo`'\([] \n,.;:?!)}>"-]\)#\1w_literal(`\2')\9#g
}}}

Underscores have two forms, depending on whether they are already
quoted.
{{{
s#\([ \n([{<"'-]\)`'w_us`'\([^ `]\(\([^`]\(`'w_apo`'\)*\(`'w[^_]\)*\(`'[^w]\)*\)*[^ `]\)*\)`'w_us`'\([] \n,.;:?!)}>"'-]\)#\1w_emph(`\2')\8#g
s#\([ \n([{<"'-]\)_\([^ _]\(\([^_]\(w_\)*\)*[^ _]\)*\)_\([] \n,.;:?!)}>"'-]\)#\1w_emph(`\2')\6#g
}}}

Other kinds of emphasis.
{{{
s#\([ \n([{<"'-]\)/\([^ /]\([^/]*[^ /]\)*\)/\([] \n,.;:?!)}>"'-]\)#\1w_techemph(`\2')\4#g
s#\([ \n([{<"'-]\)\*\([^ *]\([^*]*[^ *]\)*\)\*\([] \n,.;:?!)}>"'-]\)#\1w_strong(`\2')\4#g
}}}

Quotations are processed last to make it possible to have something
emphasised within quotes.
{{{
s#\([ \n([{<'`-]\)"\([^ "']\([^"]*[^ "]\)*\)"\([] \n,.;:?!)}>'-]\)#\1w_quotation(`\2')\4#g
}}}

Strip whitespace inserted above.
{{{
s#^ ##
s# $##
}}}