Skip to content

Commit

Permalink
html2myst: support nested <pre> in <li>, handle more ref types.
Browse files Browse the repository at this point in the history
Also removes warning about acronyms, as they're not actually
used as such in the source HTML.
  • Loading branch information
jessicah committed Aug 22, 2024
1 parent 8c66076 commit 908d553
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 27 deletions.
30 changes: 26 additions & 4 deletions html2myst/html2myst.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
operator_re = re.compile(r'(operator([+\-*\/%^&|~!=<>,()[\]]{1,3}|\s+new|\s+delete))\(')
reference_re = re.compile(r'#([^_]+)_([^_]+)$')
enum_re = re.compile(r'^([A-Z0-9_]+)$')
global_function_re = re.compile(r'([a-z]+_?)+')

def text_content(element, clean=True):
if clean:
Expand Down Expand Up @@ -402,9 +403,12 @@ def process_inline(self, element):
content += f'_{result}_'

elif child.name == 'acronym':
# no acronym support in markdown...
print(fg.li_yellow, 'WARNING: missing acronym support in markdown', reset)
# these aren't actually treated as acronyms in the source HTML,
# just a stylistic convention; will treat as plaintext, as no
# benefit to explain widely understood terms:
# AIFF, API, ASCII, ATAPI, AVI, BFS, CPU, DAC, DMA, GIF, GUI, IEC, I/O, IP, ISO, MIDI, MIME, MPEG, MUX, NTSC, PAL, PCI, PCMCIA, PNG, POP, RGB, RS-232, SCSI, SMTP, TCP, TLS, TV, UDP, URL, USB, UTF-8, VBL, WAVE
content += text_content(child)

elif child.name == 'br':
content += '\n\n'
else:
Expand Down Expand Up @@ -454,13 +458,31 @@ def process_link(self, element):
ref_method = f'{ref_class}()'
if content_matches:
if '::' in content:
# a fully qualified reference to a class method
return f'{{cpp:func}}`{ref_class}::{ref_method}()`'
else:
# a reference to a class method, with class name hidden
return f'{{cpp:func}}`~{ref_class}::{ref_method}()`'
else:
return f'{{cpp:func}}`{content} <{ref_class}::{ref_method}>`'
# a reference with a name different to link
return f'{{cpp:func}}`{content} <{ref_class}::{ref_method}>`'
else:
if ref_type == 'ref':
ref = ''

if match:
ref = match.group(0)[1:]
enum_match = enum_re.match(ref)
function_match = global_function_re.match(ref)

if match and (enum_match or function_match):
if enum_match:
return f'{{cpp:enumerator}}`{ref}`'
elif function_match:
if ref == content.replace('()', '') or ref == content:
return f'{{cpp:func}}`{ref}()`'
else:
return f'{{cpp:func}}`{content} <{ref}>`'
elif ref_type == 'ref':
print(fg.li_red, 'WARNING:', reset, 'unable to parse reference:', reset, fg.li_green, element, reset)
return f'{{{ref_type}}}`{content}`'

Expand Down
4 changes: 3 additions & 1 deletion html2myst/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ def __str__(self):
return super().wrap_content()

def wrap(self, block):
lines = str(block).split('\n')
# a block (pre) can contain explicit line breaks using '\r',
# so use `splitlines()` instead of `split('\n')`
lines = str(block).splitlines()
content = ''
for index, line in enumerate(lines):
if index == 0 and len(line) == 0:
Expand Down
14 changes: 7 additions & 7 deletions kits/application/message-filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ widths: auto
Messages that don't fit the definition won't be sent to the object's filter
function.

The {hparam}`filter` argument is a pointer to a {cpp:func}`filter_hook`
The {hparam}`filter` argument is a pointer to a {cpp:func}`filter_hook()`
function. This is the function that's invoked when a message needs to be
examined (see {cpp:func}`filter_hook` for the protocol). You don't have to
supply a {cpp:func}`filter_hook` function; instead, you can implement
examined (see {cpp:func}`filter_hook()` for the protocol). You don't have
to supply a {cpp:func}`filter_hook()` function; instead, you can implement
{hclass}`BMessageFilter`'s {cpp:func}`~BMessageFilter::Filter()` function
in a subclass.

Expand Down Expand Up @@ -122,10 +122,10 @@ outside the message-passing mechanism), but keep in mind that it's the
caller's responsibility to interpret the return value.

Rather than implement the function, you can supply the
{hclass}`BMessageFilter` with a {cpp:func}`filter_hook` callback when you
construct the object. If you do both, the {cpp:func}`filter_hook` (and not
{hmethod}`Filter()`) will be invoked when the object is asked to examine a
message.
{hclass}`BMessageFilter` with a {cpp:func}`filter_hook()` callback when you
construct the object. If you do both, the {cpp:func}`filter_hook()` (and
not {hmethod}`Filter()`) will be invoked when the object is asked to
examine a message.
::::

## Member Functions
Expand Down
10 changes: 6 additions & 4 deletions kits/application/messenger.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ The target can respond to the message:
and freeing {hparam}`reply`. {hparam}`message` and {hparam}`reply` can be
the same object.

:::{admonition} Warning :class: warning Use caution when requesting a
synchronous reply: If you call {hmethod}`SendMessage()` from the target
looper's thread, you'll deadlock (or, at best, time out). :::

- :::{admonition} Warning
:class: warning
Use caution when requesting a synchronous reply: If you call
{hmethod}`SendMessage()` from the target looper's thread, you'll deadlock
(or, at best, time out).
:::
- If you supply a reply target ({hparam}`replyMessenger` or
{hparam}`replyHandler`), the response is asynchronous, and is sent to the
reply target.
Expand Down
4 changes: 3 additions & 1 deletion kits/interface/picture.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ While many of these functions are similar to those found in
radians, rather than in degrees. You can convert the value into degrees
by using the forumla:

:::{code} cpp degrees = (rotation*180.0) / 3.14159265369); :::
- :::{code} cpp
degrees = (rotation*180.0) / 3.14159265369);
:::
::::

## Static Functions
Expand Down
7 changes: 4 additions & 3 deletions kits/storage/path.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,10 @@ Other details…

- Destructive setting is safe:

:::{code} cpp /* This works... */
path.SetTo(path.Path(), ...); :::

- :::{code} cpp
/* This works... */
path.SetTo(path.Path(), ...);
:::
- Currently, {hmethod}`SetTo()` only checks pathname and filename length if
it has to normalize.

Expand Down
2 changes: 1 addition & 1 deletion system-overview/application/message-filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To define a message filter, you have to provide a message-filtering
function. You do this by implementing the
{cpp:func}`~BMessageFilter::Filter()` hook function in a
{cpp:class}`BMessageFilter` subclass, or by supplying a
{cpp:func}`filter_hook` function to the {cpp:class}`BMessageFilter`
{cpp:func}`filter_hook()` function to the {cpp:class}`BMessageFilter`
constructor. Only one filter function per object is called. If you
implement {cpp:func}`~BMessageFilter::Filter()` and provide a filter_hook
function, the filter_hook will win.
Expand Down
5 changes: 3 additions & 2 deletions system-overview/interface/list-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ parameters:
{cpp:class}`BListItem`. All drawing calls you issue should be made
through this BView. For example:

:::{code} cpp owner->DrawString(item_text); :::

- :::{code} cpp
owner->DrawString(item_text);
:::
- A {cpp:class}`BRect`, which is the rectangle in which the item should be
drawn.

Expand Down
9 changes: 5 additions & 4 deletions topics/device-drivers/driver-settings-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ The settings file is formatted like this:
- Parameters can have values and subparameters. A parameter has the
following form in the settings file:

:::{code} sh name [value]* [{
[parameter]*
}] ['n',','] :::

- :::{code} sh
name [value]* [{
[parameter]*
}] ['n',',']
:::
Where [] indicates an optional part, and []* indicates an optional
repeated part.

Expand Down

0 comments on commit 908d553

Please sign in to comment.