jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.9k stars 3.39k forks source link

Haddock table generation wraps URLs #4572

Open expipiplus1 opened 6 years ago

expipiplus1 commented 6 years ago

To reproduce:

$ cat << EOF | pandoc --from native --to haddock
[
 Table [] [AlignDefault,AlignDefault,AlignDefault,AlignDefault] [0.25,0.25,0.25,0.25]
 [[Plain [Link ("",[],[]) [Str "Command",Space,Str "Buffer",Space,Str "Levels"] ("#VkCommandBufferLevel","")]]
 ,[Plain [Link ("",[],[]) [Str "Render",Space,Str "Pass",Space,Str "Scope"] ("#vkCmdBeginRenderPass","")]]
 ,[Plain [Link ("",[],[]) [Str "Supported",Space,Str "Queue",Space,Str "Types"] ("#VkQueueFlagBits","")]]
 ,[Plain [Link ("",[],[]) [Str "Pipeline",Space,Str "Type"] ("#synchronization-pipeline-stages-types","")]]]
 [[[Para [Str "Primary",LineBreak,Str "Secondary"]]
  ,[Para [Str "Both"]]
  ,[Para [Str "Graphics"]]
  ,[]]]
]
EOF

Observe that the links are split across several lines in the header. Many tools ingesting this output will insert a space erroneously.

> +-----------------+-----------------+-----------------+-----------------+
> | <#VkCommandBuff | <#vkCmdBeginRen | <#VkQueueFlagBi | <#synchronizati |
> | erLevel Command | derPass Render  | ts Supported Qu | on-pipeline-sta |
> |  Buffer Levels> | Pass Scope>     | eue Types>      | ges-types Pipel |
> |                 |                 |                 | ine Type>       |
> +=================+=================+=================+=================+
> | Primary         | Both            | Graphics        |                 |
> | Secondary       |                 |                 |                 |
> +-----------------+-----------------+-----------------+-----------------+

After a cursory look, it seems as though the nowrap function in just replacing spaces with non-breaking spaces, which gridTable seems to ignore.

expipiplus1 commented 6 years ago

It seems as though this is down to lblock being quite indiscriminate about where it chops text.

jgm commented 6 years ago

I'm not sure this counts as a bug. The table specifies relative column widths: 25% of total text width for each column. The only way to achieve this in a grid table is by breaking things awkwardly. You can use --columns to increase the total width, or you can use a different type of table (e.g. pipe table).

expipiplus1 commented 6 years ago

I've made an effort to correct this here: https://github.com/expipiplus1/pandoc/commit/7519805e18b78e284082085906c78d244f478a2d

When using Haddock tables, it inserts spaces at all the line breaks, causing the links to become invalid. It's not really a bug for the code block tables as a human is reading them though.

expipiplus1 commented 3 years ago

I'm not sure this counts as a bug. The table specifies relative column widths: 25% of total text width for each column. The only way to achieve this in a grid table is by breaking things awkwardly. You can use --columns to increase the total width, or you can use a different type of table (e.g. pipe table).

Increasing the columns seems a little heavy handed (although I suppose this depends on exactly what --columns means)

I'm not generating the source myself, it's being parsed from docbook, although this doesn't preclude changing grid tables to pipe tables I guess.

Would this patch be acceptable if the strictWrapping value was configurable for the Haddock writer?

jgm commented 3 years ago

I'm wondering whether we should just change the default so that (in all writers that use grid tables) breaks occur only on spaces. This issue comes up from time to time -- also in markdown.

expipiplus1 commented 3 years ago

Yeah, that would be excellent also.

jgm commented 3 years ago

I've posted something on pandoc-discuss to get feedback about the idea.

ickc commented 3 years ago

I agree that changing the default with warning message is a good solution. Width is not as important to be enforced in this situation. And since either way is a compromised solution, emitting a warning about non perfect output is better than just handling it silently.

In the current behavior, round tripping back to the AST means something totally different, so there shouldn't be any need to have an option to choose the old behavior?

I wonder how the widths would change: only that column or scaling up the whole table proportionally?

jgm commented 3 years ago

only that column or scaling up the whole table proportionally?

just that column