Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bold formatting does not work in headings #113

Open
Mr0grog opened this issue Nov 29, 2023 · 0 comments · May be fixed by #158
Open

Bold formatting does not work in headings #113

Mr0grog opened this issue Nov 29, 2023 · 0 comments · May be fixed by #158
Labels
bug Something isn't working

Comments

@Mr0grog
Copy link
Owner

Mr0grog commented Nov 29, 2023

If part of a heading is bold in a Google doc, the bold text does not get surrounded with ** bold markdown sytnax — except in Firefox.

For example, in this document: https://docs.google.com/document/d/1lU6N1g5jmyvxZebY1JZpdVtS5SOLlaf65i1b7FilRfY/

Screenshot of above linked document

Results in the following markdown on Safari and Chrome:

# Heading with bold and _emphasized_ text

Normal text

In Firefox, the bold is preserved, and you get this output:

# Heading with **bold** and _emphasized_ text

Normal text

I think what we’re gettin in Firefox is better, and we should make sure this happens in other browsers, too. (Even though Markdown is really a shortcut syntax for HTML and most HTML renderers will already make the heading bold, there is semantic meaning here worth preserving. And some Markdown renderers might handle this case specially and still differentiate the text from the rest of the heading somehow.)

As far as why this happens: Google Docs wraps the content of headings in <span style="font-weight: 400"> (for normal text) and in <span style="font-weight: 700"> (for explicitly bolded text) the same as anywhere else in a document. But some browsers (WebKit and Chrome, but not Firefox; I’m not sure about other more niche engines) normalize the styling of the bolded text by removing the font-weight property, since the weight can be inherited from the heading it’s in (since the browser’s default styling of the heading is to make it bold).

I can see two obvious approaches to solving this:

  1. Identify headers where some text has font-weight: 400 or font-weight: normal and other text has no font-weight at all, and update the latter text to be bold.
  2. When resolving styles in lib/css.js, include some default styles for some elements (in this case font-weight: bold for headings).

The second approach is probably simpler, but it might result in unnecessarily bolding text in headings that are pasted in from other web pages, e.g:

# **Heading Text**

While non-Google-Docs source HTML is not our primary concern here, it would be nice not to make it worse than the current situation.

Note: this was originally mixed in a bit subtly with the tests in #104; I’m extracting it into a separate issue here.

Mr0grog added a commit to trustedtomato/google-docs-to-markdown that referenced this issue Nov 29, 2023
This simplifies the `internal-links` test fixture a bit in order to keep it focused. This also removes some complicated markup around boldness in the headings because things get complicated there, and made a separate issue about it: Mr0grog#113.

I've also moved the fixture to our official GDocs fixture folder.
@Mr0grog Mr0grog added the bug Something isn't working label Nov 29, 2023
Mr0grog added a commit that referenced this issue Feb 3, 2024
Mr0grog added a commit that referenced this issue Feb 3, 2024
Fixes #113 by looking for headings with a mix of children with normal/400 weight and no set weight, then updating the children with no set weight to be bold.
@Mr0grog Mr0grog linked a pull request Feb 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant