summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/tex4ht/piton.4ht
blob: b1140b4094b46de978a737881e55703e63fd961e (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
% piton.4ht (2023-10-13-14:15), generated from tex4ht-4ht.tex
% Copyright 2023 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2023-10-13-14:15}


\ExplSyntaxOn

\NewConfigure{pitonline}{3}
\NewConfigure{pitonnumber}{2}
\protected\def\:tempa #1\__piton_end_line:{
  \:pitonendignorelines\glet\:pitonendignorelines\relax
  \group_begin:
  % we set line in a box, because otherwise lines are collapsed sometimes
  \hbox_set:Nn \l_tmpa_box{
  \a:pitonline
  \a:pitonnumber
  \bool_if:NT \l__piton_line_numbers_bool
  {
  \bool_if:nF
    {
      \str_if_eq_p:nn { #1 } { \PitonStyle {Prompt}{} }
      &&
      \l__piton_skip_empty_lines_bool
    }
    { \int_gincr:N \g__piton_visual_line_int}

  \bool_if:nT
    {
      ! \str_if_eq_p:nn { #1 } { \PitonStyle {Prompt}{} }
      ||
      ( ! \l__piton_skip_empty_lines_bool && \l__piton_label_empty_lines_bool )
    }
    \__piton_print_number:
  }
  \b:pitonnumber
  \language = -1
  \raggedright
  \strut
  % \HCode{<code>}
  \b:pitonline
  \NoFonts
  \__piton_replace_spaces:n { #1 }
  \EndNoFonts
  %
  \c:pitonline
  }
  \box_use_drop:N \l_tmpa_box
  \group_end:
}
\HLet\__piton_begin_line:\:tempa


\NewConfigure{piton}{2}

% Piton environments and file input produces extra blank line at the start
% we use TeX4ht specials to remove them
\gdef\:pitonendignorelines{}
\pend:def\__piton_pre_env:{\a:piton
  \ht:special{t4ht@[}% ignore next linebreak, to preven spurious blank line at the beginning of listings
  \gdef\:pitonendignorelines{\ht:special{t4ht@]}}
}
\append:def\__piton_write_aux:{\b:piton}


\NewDocumentCommand { \:__piton_piton_standard } { m }
  {
    \group_begin:
    \ttfamily
    \a:pitonline\b:pitonline
    \automatichyphenmode = 1
    \cs_set_eq:NN \\ \c_backslash_str
    \cs_set_eq:NN \% \c_percent_str
    \cs_set_eq:NN \{ \c_left_brace_str
    \cs_set_eq:NN \} \c_right_brace_str
    \cs_set_eq:NN \$ \c_dollar_str
    \cs_set_eq:cN { ~ } \space
    \cs_set_protected:Npn \__piton_begin_line: { }
    \cs_set_protected:Npn \__piton_end_line: { }
    \tl_set:Ne \l_tmpa_tl
      {
        \lua_now:e
          { piton.ParseBis('\l__piton_language_str',token.scan_string()) }
          { #1 }
      }
    \bool_if:NTF \l__piton_show_spaces_bool
      { \regex_replace_all:nnN { \x20 } { ^^^^2423  } \l_tmpa_tl } % U+2423
      {
        \bool_if:NT \l__piton_break_lines_in_piton_bool
          { \regex_replace_all:nnN { \x20 } { \x20 } \l_tmpa_tl }
      }
      % our extra code to remove the space glyph
    \regex_replace_all:nnN { \x20 } { \c { __piton_breakable_space: } } \l_tmpa_tl
    \l_tmpa_tl
    \c:pitonline
    \group_end:
  }

\HLet\__piton_piton_standard\:__piton_piton_standard

\NewDocumentCommand { \:__piton_piton_verbatim } { v }
  {
    \group_begin:
    \ttfamily
    \a:pitonline\b:pitonline
    \automatichyphenmode = 1
    \cs_set_protected:Npn \__piton_begin_line: { }
    \cs_set_protected:Npn \__piton_end_line: { }
    \tl_set:Ne \l_tmpa_tl
      {
        \lua_now:e
          { piton.Parse('\l__piton_language_str',token.scan_string()) }
          { #1 }
      }
    \bool_if:NT \l__piton_show_spaces_bool
      { \regex_replace_all:nnN { \x20 } { ^^^^2423  } \l_tmpa_tl } % U+2423
    % our extra code to remove the space glyph
    \regex_replace_all:nnN { \x20 } { \c { __piton_breakable_space: } } \l_tmpa_tl
    \l_tmpa_tl
    \c:pitonline
    \group_end:
  }

\HLet\__piton_piton_verbatim\:__piton_piton_verbatim

\ExplSyntaxOff
\Hinput{piton}
\endinput