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

Special Formatting Not Working #142

Closed
yamsu opened this issue Jul 11, 2023 · 5 comments
Closed

Special Formatting Not Working #142

yamsu opened this issue Jul 11, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@yamsu
Copy link

yamsu commented Jul 11, 2023

Hi, I'm unable to add superscript or subscripts in bullets and tables.
I have updated the repo and tested on python 3.11 & 3.8
This is the markdown (Removed all meta options and templates). Incidentally, I get the same error with or without the metadata

# Presentation

### Special Formatting

* Bold : **Bold**
* italics : *italics*
* A<sub>6</sub>

This is the error:

Traceback (most recent call last):
  File ".../usr/bin/md2pptx", line 6525, in <module>
    slideNumber, slide, sequence = createSlide(prs, slideNumber, slideInfo)
  File ".../usr/bin/md2pptx", line 4199, in createSlide
    slide = createContentSlide(
  File ".../usr/bin/md2pptx", line 2613, in createContentSlide
    createListBlock(slideInfo, slide, renderingRectangle)
  File ".../usr/bin/md2pptx", line 2885, in createListBlock
    renderText(bulletsShape, slideInfo.bullets)
  File ".../usr/bin/md2pptx", line 1028, in renderText
    addFormattedText(p, bullet[1])
  File ".../usr/bin/md2pptx", line 1748, in addFormattedText
    set_subscript(font)
  File ".../usr/bin/md2pptx", line 794, in set_subscript
    if font.size < Pt(24):
TypeError: '<' not supported between instances of 'NoneType' and 'Pt'
  • Using pdb font.size is indeed NoneType
@MartinPacker
Copy link
Owner

MartinPacker commented Jul 11, 2023

Investigating. I'm wondering how the font object came to not exist or else no have a size attribute.

Anyhow I've recreated this - thanks to your sample markdown, @yamsu.

@MartinPacker
Copy link
Owner

So we definitely have a font object passed into set_subscript - but it has no size attribute.

@MartinPacker
Copy link
Owner

MartinPacker commented Jul 11, 2023

And it has nothing to do with the previous bullets; It's all about the <sub> element. (Actually <sup> triggers the same error.)

@MartinPacker
Copy link
Owner

MartinPacker commented Jul 11, 2023

So it seems when python-pptx's add_run method is called - for a paragraph object - it doesn't set the font size for the new run. Normally that doesn't matter. In the case of handling <sub> and <sup> it matters because the font size is queried in add_subscript and add_superscript, respectively.

If the run's font size is less than 24 points the baseline is dropped / raised by one amount. If greater a larger baseline adjustment is done. (This all appears to be how Powerpoint itself does it.)

The solution for now is to test the run's font size. If it doesn't exist the code assumes the smaller baseline adjustment.

I've tested this and it works. I'll investigate documentation and push this out in the next hour - as 4.1.2. (There's another urgent fix - for card slides - I need to get out.)

@MartinPacker MartinPacker added the bug Something isn't working label Jul 11, 2023
@MartinPacker
Copy link
Owner

Documented (with additional explanations as to how <sub> and <sup> work) and released as v4.1.2.

Thanks for the bug report @yamsu!

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

No branches or pull requests

2 participants