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

No way to split up long lines in a grid table cell #4943

Closed
garethstockwell opened this issue Oct 1, 2018 · 3 comments
Closed

No way to split up long lines in a grid table cell #4943

garethstockwell opened this issue Oct 1, 2018 · 3 comments

Comments

@garethstockwell
Copy link

garethstockwell commented Oct 1, 2018

The width of a table column in Markdown can be used to control the width of the rendered column.
However, if the source includes markup (for example cross-references) which are wider than the column, these are incorrectly parsed. This can be fixed by widening the column ... but then the appearance of the rendered table changes.

Here is an example, to be rendered using

pandoc --filter pandoc-crossref test.md -o test.pdf

Example test.md:

---
# pandoc-crossref configuration
numbersections: true
---


# Desired output

This is the desired table column width:

+------------------+------------------+-----------------------+
| Fruit            | Price            | Advantages            |
+==================+==================+=======================+
| Bananas          | 0.75             | -   built-in wrapper  |
|                  |                  | -   bright color      |
+------------------+------------------+-----------------------+
| Oranges          | 0.99             | -   cures scurvy      |
|                  |                  | -   tasty             |
+------------------+------------------+-----------------------+


# Short labels

I can put a link to a short label into the table like this:

+------------------+------------------+-----------------------+
| Fruit            | Price            | Advantages            |
+==================+==================+=======================+
|                  |                  | See [@sec:short]      |
+------------------+------------------+-----------------------+


# Long labels

But if I put a long link (wrapped) into the table, it is not parsed correctly:

+------------------+------------------+-----------------------+
| Fruit            | Price            | Advantages            |
+==================+==================+=======================+
|                  |                  | See [@sec:section-with|
|                  |                  |-a-very-long-label]    |
+------------------+------------------+-----------------------+


# Wide columns

I can expand the width of the column, to avoid wrapping the label - but this changes the rendered width, which I don't want:

+------------------+------------------+-------------------------------------------+
| Fruit            | Price            | Advantages                                |
+==================+==================+===========================================+
|                  |                  | See [@sec:section-with-a-very-long-label] |
+------------------+------------------+-------------------------------------------+


# Workaround

I could express the desired width of the table columns using a wrapper div, and then write a filter to scan for these and adjust widths - but I was hoping for a native solution.

<div table-column-width="0.2 0.2 0.3">

+------------------+------------------+-------------------------------------------+
| Fruit            | Price            | Advantages                                |
+==================+==================+===========================================+
|                  |                  | See [@sec:section-with-a-very-long-label] |
+------------------+------------------+-------------------------------------------+

</div>


# A better solution?

Could a continuation character be used, to indicate that a piece of markup has been broken across multiple lines in the cell?

+------------------+------------------+-----------------------+
| Fruit            | Price            | Advantages            |
+==================+==================+=======================+
|                  |                  | See [@sec:section-wit\|
|                  |                  |h-a-very-long-label]   |
+------------------+------------------+-----------------------+


# Section with a short label {#sec:short}

This section is here to serve as the target of hyperlinks from elsewhere in the document.


# Section with a long label {#sec:section-with-a-very-long-label}

This section is here to serve as the target of hyperlinks from elsewhere in the document.
@jgm
Copy link
Owner

jgm commented Oct 1, 2018 via email

@jgm jgm changed the title Markup broken across lines within table cell is incorrectly parsed No way to split up long lines in a grid table cell Oct 9, 2018
@lspitzner
Copy link

#5639 might address this as a new markdown table extension.

@tarleb
Copy link
Collaborator

tarleb commented May 20, 2021

There doesn't seem to be a good solution, so I'm closing this.

FWIW, I've been using the Unicode "soft hyphen" character for this purpose, combined with the following Lua filter:

-- Removes spaces and soft linebreaks after "SOFT HYPHEN" Unicode
-- characters. It doesn't make sense for a soft hyphen to be followed by
-- a space, so we can use it to re-join words, e.g. after wrapping them
-- to fit small table columns.

local text = require 'text'

function space_after_soft_hyphen (left, right)
  return left and left.t == 'Str' and text.sub(left.text, -1) == '­'
    and right and (right.t == 'Space' or right.t == 'SoftBreak')
end

function Inlines (inlns)
  for i = #inlns - 1, 1, -1 do
    if space_after_soft_hyphen(inlns[i], inlns[i+1]) then
      -- LaTeX doesn't use soft hyphens for hyphenation. Replace with
      -- LaTeX specific syntax.
      if FORMAT:match 'latex' then
        inlns[i].text = text.sub(inlns[i].text, 1, -1)
        inlns[i+1] = pandoc.RawInline('latex', '\\-')
      else
        inlns:remove(i+1)
      end
    end
  end
  return inlns
end

@tarleb tarleb closed this as completed May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants