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

Multiline codeblocks seen as "superscript" instead of "code" block in confluence #12

Closed
nado opened this issue Feb 3, 2024 · 10 comments · Fixed by #26
Closed

Multiline codeblocks seen as "superscript" instead of "code" block in confluence #12

nado opened this issue Feb 3, 2024 · 10 comments · Fixed by #26
Assignees

Comments

@nado
Copy link

nado commented Feb 3, 2024

Pretty much what the title says, I upload a README file with the following content being rendered incorrectly. Inline code renders fine.

` ` `ps1
git init
echo * > .gitignore
git remote add origin git@server
git fetch
git checkout origin/master -b master
` ` `
@szn szn self-assigned this Sep 11, 2024
szn added a commit that referenced this issue Sep 11, 2024
@szn szn linked a pull request Sep 11, 2024 that will close this issue
@szn
Copy link
Owner

szn commented Sep 11, 2024

There is a temporary hack to bypass the problem but I am not happy with the results.

Remember that only bare code blocks work (without language specification in the first line).

$ pip install --upgrade confluence.md

@szn szn closed this as completed Sep 11, 2024
@mxmo0rhuhn
Copy link

@szn A CI job that runs on an unchanged README.md file of me fails now (since using the new version):

requests.exceptions.HTTPError: com.atlassian.confluence.api.service.exceptions.BadRequestException: Content body cannot be converted to new editor format

Is there any way that I can extract the HTML for debugging?

@szn szn reopened this Sep 13, 2024
@szn
Copy link
Owner

szn commented Sep 13, 2024

Sad to hear that @mxmo0rhuhn.

Please install a dev version to see a raw HTML log:

$ pip install --upgrade --index-url https://test.pypi.org/simple/ confluence.md==0.4.7.dev1

And run a command with -v option.

@mxmo0rhuhn
Copy link

Hello,
I was able to reproduce the issue with the code block.

Working

a file like this:

# Hello world

resulting in a page like this:

    <p><strong>Automatic content</strong> - Do not edit this page in Confluence.
    Page automatically generated from: <code>test.md</code></p><hr />
    <h1>Hello world</h1>

Not working

a file like this:

    # Hello world

    a file like this should be converted to a confluence page

    ```markdown
    # Hello world
    ```

resulting in a page like this:

    <p><strong>Automatic content</strong> - Do not edit this page in Confluence.
    Page automatically generated from: <code>test_code.md</code></p><hr />
    <h1>Hello world</h1>

<p>a file like this should be converted to a confluence page</p>

<div class="codehilite">
<pre><span></span><code><span class="gh"># Hello world</span>
</code>
</div>

which is subsequently not accepted by the confluence API:

requests.exceptions.HTTPError: com.atlassian.confluence.api.service.exceptions.BadRequestException: Content body cannot be converted to new editor format

At first glance, it looks to me like there is a <pre> tag generated that is not used and not closed.

szn added a commit that referenced this issue Sep 16, 2024
@szn
Copy link
Owner

szn commented Sep 16, 2024

Thanks @mxmo0rhuhn

I am not proud of this fix but it seems to work:

pip install --upgrade --index-url https://test.pypi.org/simple/ confluence.md==0.4.7.dev2

I believe I reached the limits of markdown2 package. For code blocks to render properly I would need to either replace the md2html translator or perform more intense HTML post-processing. Marked as TODO.

@mxmo0rhuhn
Copy link

Thank you for the super fast fix! There is a special case that does not work now:

```bash
echo "hello, world!"
```

```python
print("hello, world!")
```

resulting in a page like this:

    <p><strong>Automatic content</strong> - Do not edit this page in Confluence.
    Page automatically generated from: <code>test_code.md</code></p><hr />
    <div class="codehilite">
<code><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;Hello, World!&quot;</span>
</code>
</div>

<div class="codehilite">
<pre><span></span><code><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Hello, World!&quot;</span><span class="p">)</span>
</code>
</div>

from a first look it seems like in this setup the regex is not able to match the opening <pre> tag. interestingly, if there is only one code block in the file, the <pre> tag is matched correctly and the upload works as expected.

@szn
Copy link
Owner

szn commented Sep 17, 2024

Aaaand:

pip install --upgrade --index-url https://test.pypi.org/simple/ confluence.md==0.4.7.dev3

:)

@mxmo0rhuhn
Copy link

Yay it works! All files that I tested with were correctly uploaded to Confluence 👍

Thanks a lot for your continued effort!

@szn
Copy link
Owner

szn commented Sep 17, 2024

Thanks for testing!

@szn szn closed this as completed Sep 17, 2024
szn added a commit that referenced this issue Sep 17, 2024
@szn
Copy link
Owner

szn commented Sep 17, 2024

@mxmo0rhuhn 0.4.7.dev3 was published as 0.4.8 (except debug html log). You can:

$ pip install --upgrade confluence.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants