From f66db0c41c3da640b9ba7441ebc1e52400c4a34d Mon Sep 17 00:00:00 2001 From: timsong-cpp Date: Fri, 13 Nov 2020 18:58:21 -0600 Subject: [PATCH 1/7] Add numbered notes --- data/filters/wg21.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/data/filters/wg21.py b/data/filters/wg21.py index c10c6b5..31d0497 100755 --- a/data/filters/wg21.py +++ b/data/filters/wg21.py @@ -295,11 +295,11 @@ def _color(html_color): pf.RawInline('}', 'latex')) elem.attributes['style'] = f'color: #{html_color}' - def _nonnormative(name): + def _nonnormative(name, number='?'): wrap_elem( - pf.Span(pf.Str('[ '), pf.Emph(pf.Str(f'{name.title()}:')), pf.Space), + pf.Span(pf.Str('[\xa0'), pf.Emph(pf.Str(f'{name.title()} {number}:')), pf.Space), elem, - pf.Span(pf.Str(' — '), pf.Emph(pf.Str(f'end {name.lower()}')), pf.Str(' ]'))) + pf.Span(pf.Str(' —\xa0'), pf.Emph(pf.Str(f'end {name.lower()}')), pf.Str('\xa0]'))) def _diff(color, latex_tag, html_tag): if isinstance(elem, pf.Span): @@ -334,8 +334,8 @@ def pnum(): return pf.Superscript(pf.Str(num)) - def example(): _nonnormative('example') - def note(): _nonnormative('note') + def example(number='?'): _nonnormative('example', number) + def note(number='?'): _nonnormative('note', number) def ednote(): wrap_elem(pf.Str("[ Editor's note: "), elem, pf.Str(' ]')) _color('0000ff') @@ -366,11 +366,11 @@ def rm(): _diff('rmcolor', 'sout', 'del') pf.debug('mpark/wg21: stable name', target, 'not found') return link - note_cls = next(iter(cls for cls in elem.classes if cls in {'example', 'note', 'ednote', 'draftnote'}), None) - if note_cls == 'example': example() - elif note_cls == 'note': note() - elif note_cls == 'ednote': ednote(); return - elif note_cls == 'draftnote': draftnote(); return + for cls in elem.classes: + if cls.startswith('note'): note(cls[4:] or '?') + elif cls.startswith('example'): example(cls[7:] or '?') + elif note_cls == 'ednote': ednote(); return + elif note_cls == 'draftnote': draftnote(); return diff_cls = next(iter(cls for cls in elem.classes if cls in {'add', 'rm'}), None) if diff_cls == 'add': add() From 0879f7fdaeb1e14917696d59170ee3d94250dbd0 Mon Sep 17 00:00:00 2001 From: timsong-cpp Date: Thu, 19 Nov 2020 18:56:07 -0600 Subject: [PATCH 2/7] strip markdown by converting to plain --- data/filters/wg21.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/filters/wg21.py b/data/filters/wg21.py index 31d0497..aa20b8d 100755 --- a/data/filters/wg21.py +++ b/data/filters/wg21.py @@ -39,7 +39,7 @@ def prepare(doc): doc.metadata['pagetitle'] = pf.convert_text( pf.Plain(*doc.metadata['title'].content), input_format='panflute', - output_format='markdown') + output_format='plain') datadir = doc.get_metadata('datadir') From 6605454fe3043adc51ba4208f1450394f7575194 Mon Sep 17 00:00:00 2001 From: timsong-cpp Date: Thu, 19 Nov 2020 18:59:33 -0600 Subject: [PATCH 3/7] strip newline --- data/filters/wg21.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/filters/wg21.py b/data/filters/wg21.py index aa20b8d..5bd189a 100755 --- a/data/filters/wg21.py +++ b/data/filters/wg21.py @@ -44,7 +44,7 @@ def prepare(doc): datadir = doc.get_metadata('datadir') with open(os.path.join(datadir, 'annex-f'), 'r') as f: - stable_names.update(line.split(maxsplit=1) for line in f) + stable_names.update(line.rstrip().split(maxsplit=1) for line in f) def highlighting(output_format): return pf.convert_text( From f8f5c7de3da555ab4eac1a2e0cef3620ad522729 Mon Sep 17 00:00:00 2001 From: timsong-cpp Date: Fri, 28 May 2021 18:21:50 -0500 Subject: [PATCH 4/7] Support using # to automatically number paragraphs --- data/filters/wg21.py | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/data/filters/wg21.py b/data/filters/wg21.py index 5bd189a..4dd88ac 100755 --- a/data/filters/wg21.py +++ b/data/filters/wg21.py @@ -15,6 +15,7 @@ embedded_md = re.compile('@@(.*?)@@|@(.*?)@') stable_names = {} +current_pnum = {} refs = {} def wrap_elem(opening, elem, closing): @@ -320,8 +321,51 @@ def protect_code(elem, doc): _color(doc.get_metadata(color)) def pnum(): + global current_pnum num = pf.stringify(elem) + depth = num.count('.') + parts = num.split('.') + + def reset_below(i): + to_delete = [k for k in current_pnum if k > i] + for k in to_delete: + del current_pnum[k] + + # If we see a level N, always reset levels below it. + reset_below(depth) + + for i in range(len(parts)): + # placeholder pnum parts are expressed by # + if parts[i] == '#': + # replace placeholder by: + # - last used value if this is not the last part + # - last used value + 1 otherwise + if i == depth: + pt = current_pnum.get(i, 0) + 1 + parts[i] = str(pt) + current_pnum[i] = pt + else: + pt = current_pnum.get(i) + if pt is None: + pf.debug('Missing current value for non-lowest-level placeholder in {}'.format(num)) + pt = 1 + current_pnum[i] = pt + reset_below(i) + parts[i] = str(pt) + else: + try: + val = int(parts[i]) + if i not in current_pnum or current_pnum[i] != val: + current_pnum[i] = val + # When we see a new value at a level, + # reset everything below that level. + reset_below(i) + except ValueError: + pass + + num = '.'.join(parts) + if '.' in num: num = f'({num})' @@ -348,6 +392,11 @@ def draftnote(): def add(): _diff('addcolor', 'uline', 'ins') def rm(): _diff('rmcolor', 'sout', 'del') + if isinstance(elem, pf.Header): + # When entering a new section, reset auto paragraph numbering. + global current_pnum + current_pnum = {} + if not any(isinstance(elem, cls) for cls in [pf.Div, pf.Span]): return None From 4e713ab8eecb71df3f18ed9e57cc1936bc9f68ca Mon Sep 17 00:00:00 2001 From: timsong-cpp Date: Fri, 28 May 2021 19:42:41 -0500 Subject: [PATCH 5/7] autonumbering notes/examples too --- data/filters/wg21.py | 45 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/data/filters/wg21.py b/data/filters/wg21.py index 4dd88ac..7a18dab 100755 --- a/data/filters/wg21.py +++ b/data/filters/wg21.py @@ -16,6 +16,9 @@ embedded_md = re.compile('@@(.*?)@@|@(.*?)@') stable_names = {} current_pnum = {} +current_note = 0 +current_example = 0 + refs = {} def wrap_elem(opening, elem, closing): @@ -393,9 +396,11 @@ def add(): _diff('addcolor', 'uline', 'ins') def rm(): _diff('rmcolor', 'sout', 'del') if isinstance(elem, pf.Header): - # When entering a new section, reset auto paragraph numbering. - global current_pnum + # When entering a new section, reset all auto numbering. + global current_pnum, current_example, current_note current_pnum = {} + current_example = 0 + current_note = 0 if not any(isinstance(elem, cls) for cls in [pf.Div, pf.Span]): return None @@ -416,10 +421,38 @@ def rm(): _diff('rmcolor', 'sout', 'del') return link for cls in elem.classes: - if cls.startswith('note'): note(cls[4:] or '?') - elif cls.startswith('example'): example(cls[7:] or '?') - elif note_cls == 'ednote': ednote(); return - elif note_cls == 'draftnote': draftnote(); return + if cls.startswith('note'): + num = cls[4:] + if num == '-': + num = '?' + elif num: + try: + current_note = int(num) + except ValueError: + pass + else: + current_note = current_note + 1 + num = str(current_note) + note(num) + elif cls.startswith('example'): + num = cls[7:] + if num == '-': + num = '?' + elif num: + try: + current_example = int(num) + except ValueError: + pass + else: + current_example = current_example + 1 + num = str(current_example) + example(num) + elif note_cls == 'ednote': + ednote() + return + elif note_cls == 'draftnote': + draftnote() + return diff_cls = next(iter(cls for cls in elem.classes if cls in {'add', 'rm'}), None) if diff_cls == 'add': add() From 5e76b06906d1ed5377923cfde376204eb03c2f44 Mon Sep 17 00:00:00 2001 From: timsong-cpp Date: Sun, 30 May 2021 11:18:21 -0500 Subject: [PATCH 6/7] Make pnums into links --- data/filters/wg21.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/data/filters/wg21.py b/data/filters/wg21.py index 7a18dab..b5477bd 100755 --- a/data/filters/wg21.py +++ b/data/filters/wg21.py @@ -18,6 +18,7 @@ current_pnum = {} current_note = 0 current_example = 0 +current_pnum_count = 0 refs = {} @@ -372,11 +373,15 @@ def reset_below(i): if '.' in num: num = f'({num})' + global current_pnum_count + current_pnum_count = current_pnum_count + 1 + if doc.format == 'latex': return pf.RawInline(f'\\pnum{{{num}}}', 'latex') elif doc.format == 'html': return pf.Span( - pf.RawInline(f'{num}', 'html'), + pf.RawInline(f'{num}', 'html'), classes=['marginalizedparent']) return pf.Superscript(pf.Str(num)) From f78462015e88bbab8c0232380a0f4bcfd1f371b6 Mon Sep 17 00:00:00 2001 From: Barry Revzin Date: Wed, 1 Jan 2025 11:01:22 -0600 Subject: [PATCH 7/7] Missed variable rename --- data/filters/wg21.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/filters/wg21.py b/data/filters/wg21.py index b5477bd..5b2b66a 100755 --- a/data/filters/wg21.py +++ b/data/filters/wg21.py @@ -452,10 +452,10 @@ def rm(): _diff('rmcolor', 'sout', 'del') current_example = current_example + 1 num = str(current_example) example(num) - elif note_cls == 'ednote': + elif cls == 'ednote': ednote() return - elif note_cls == 'draftnote': + elif cls == 'draftnote': draftnote() return