Is it possible to have a table in the center in a GitHub gist Markdown? - github

Is it possible to have a table in the center in a GitHub gist Markdown? If so, how?
I've used the following syntax to create a table on a Markdown file:
Somehow the table is always flushed to the left!!!
|Column1|Column1|Column1|
|:----|:----:|----:|
|Column1|Column1|Column1|
But the table is flushed left, see https://gist.github.com/alvations/5095d3bcc0eec357c78f1c21a49e334f
Is it possible to have the table at the center of the page when viewing?
I've tried the suggestion from Is it possible to center tables in a markdown file? to use:
Somehow the table is always flushed to the left!!!
<center>
|Column1|Column1|Column1|
|:----|:----:|----:|
|Column1|Column1|Column1|
</center>
And the table disappears when viewing, see https://gist.github.com/alvations/cd3495e7107b7701cf1cf1da2a839534
I've also tried How do I center an image in the README.md on GitHub?:
Still on the left!!!
<p align="center">
|Column1|Column1|Column1|
|:----|:----:|----:|
|Column1|Column1|Column1|
</p>
But it's still on the left, see https://gist.github.com/alvations/23c18681df7a6bbf175d0e8c2cfccba3
Images for all three versions above:

In short, it's not possible. GitHub does not allow you to define your own styling.
First, note that there is no mention of the ability to apply any styling to any block level types in the GitHub Flavored Markdown spec (see the tables section). As your examples show, you are aware that you can center text within table cells, but that only applies to the cells and has no effect on the parent table (which is how HTML and CSS work and is not specific to Markdown or GitHub).
There are a few ways to define custom styles for HTML (which Markdown generates), but GitHub does not permit them.
One such way is to define CSS rules. However, right in the spec, GitHub explicitly states that they do not allow <style> tags.
Another way is to include raw HTML right in the Markdown document (with inline styles). However, for security reasons, GitHub is very selective about what they allow. In the Markup project they define the filters they apply to all markup languages they support (including, but not limited to Markdown). In pertinent part, the docs explain (emphasis added):
The HTML is sanitized, aggressively removing things that could harm you and your kin—such as script tags, inline-styles, and class or id attributes. See the sanitization filter for the full whitelist.
Given the above, it is simply not possible to define your own styling for documents hosted on GitHub. That said, some expect to be able to define styling within the Markdown syntax itself. However, the original Markdown rules explain (emphasis added):
Markdown’s syntax is intended for one purpose: to be used as a format for writing for the web.
Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags. The idea is not to create a syntax that makes it easier to insert HTML tags. In my opinion, HTML tags are already easy to insert. The idea for Markdown is to make it easy to read, write, and edit prose. HTML is a publishing format; Markdown is a writing format. Thus, Markdown’s formatting syntax only addresses issues that can be conveyed in plain text.
For any markup that is not covered by Markdown’s syntax, you simply use HTML itself.
As it is not a "publishing format," providing a way to style your document is out-of-scope for Markdown. Which leaves us with the ways which GitHub explicitly disallows. Therefore it is not possible to center a table (or apply any other custom styling) on GitHub.
As an aside, while GitHub uses the CommonMark spec (with extensions) rather than the original Markdown Rules, I make reference to the original rules as the section I quote from discusses the philosophy behind various design decisions made when creating Markdown. Markdown's (and CommonMark's) behaviors are directly related to that philosophy. While the CommonMark spec does not get into the design decisions (expect when it differs from Markdown), it does make reference to some of the points discussed in the very paragraph I quoted above. And nowhere does it contradict that philosophy. Therefore, I consider it relevant to the expectations we should have about what is and what is not part of CommonMark, and by extension, GitHub Flavored Markdown.
For completness, let's examine each of the examples provided by the OP.
The first example is simply a table with the middle column aligned "center". If we "view source" (or use the browser's "inspect" tool), we see the following HTML was generated:
<table>
<thead>
<tr>
<th align="left">Column1</th>
<th align="center">Column1</th>
<th align="right">Column1</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Column1</td>
<td align="center">Column1</td>
<td align="right">Column1</td>
</tr>
</tbody>
</table>
Note that align="center" is only defined on the middle cell of each row. As such styling is only inherited by children elements, not parent elements, this does not get applied to the the table as a whole.
As an aside, the align attribute is not even mentioned in the HTML5 spec (that I could find); however, in the HTML 4.01 spec, you can define an align attribute on a table element or any of its children which is then inherited by the children of that element only.
Of course as established above, Markdown does not provide a mechanism to define alignment on anything except the cells. But even if you could define align on the table element, the spec explains that "[t]his attribute specifies the alignment of data and the justification of text in a cell."
Therefore, if would still have no effect on how the table is positioned in its parent element.
The second example is a table wrapped in a <center> element. A look at the source HTML reveals that the <center> tag was stripped out.
In fact, a look at GitHub's whitelisted elements reveals that center elements are not allowed and stripped out.
The third example attempts to wrap the table in a paragraph with align="center" defined on the paragraph. However, note the (interpreted) HTML:
<p align="center"></p>
<table>
<thead>
<tr>
<th align="left">Column1</th>
<th align="center">Column1</th>
<th align="right">Column1</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Column1</td>
<td align="center">Column1</td>
<td align="right">Column1</td>
</tr>
</tbody>
</table>
<p></p>
According to the HTML5 spec:
A p element's end tag may be omitted if the p element is immediately followed by an... table... element.
Therefore, the paragraph does not actually wrap the table, but is implicitly closed by the table's opening tag.
But that got me curious. What if you used a div instead of a paragraph. But that makes no difference. As we've established earlier, the align attribute only effects cell text. You need to assign a style to change the position of a table on the page and Github explicitly disallows defining your own styles.

As you can see in the following image, GitHub automatically renders tables so that they're already taking up the full width. Because of this, you cannot center the text that GitHub's Markdown renderer generates (aka the table is really, really fat and technically already centered).

So totally possible !
 
<div align="center">
COLUMN 1 | </br>COLUMN 2 | </br></br>COLUMN 3
:--- | :---: | ---:
</br></br>left | center | </br></br>right
</div>
: Spacer
</br> : Skip line
:--- : Left
:---: : Center
---: : Right

It is possible to center a table. Essentially, on GitHub the table is already width 100%. You just need to give the tbody enough content for it take up 100% width too.
The trick: fill it with spaces.
<table>
<tbody>
<tr>
<td align="center">Key Features<br>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
</td>
<td align="center">Examples<br>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
</td>
<td align="center">Supported Methods<br>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
</td>
</tr>
</tbody>
</table>
Result:
Narrow browser window:

Using mathjax:
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML-full"></script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({"HTML-CSS": { preferredFont: "TeX", availableFonts:["STIX","TeX"], linebreaks: { automatic:true }, EqnChunk:(MathJax.Hub.Browser.isMobile ? 10 : 50) }, tex2jax: { inlineMath: [ ["$", "$"], ["\\\\(","\\\\)"] ], displayMath: [ ["$$","$$"], ["\\[", "\\]"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno" }, TeX: { noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } }, Macros: { href: "{}" } }, messageStyle: "none" }); </script>
$$
\begin{array}{|c|c|c|}
\hline
\textbf{Column1} & \textbf{Column1} & \textbf{Column1} \\
\hline
\text{Column1} & \text{Column1} & \text{Column1} \\
\hline
\end{array}
$$

Just add align="center" into tag table
<table align="center"></table>

Related

Selenium IDE target of subsequent cell in table based on first cells content

Basically, in English I want to tell Selenium "look for the content ttc202 in column one, of a multi-row, multicolumn table, then mouseOver on the Edit link"
HTML is as follows:
<tr id="86" class="ui-widget-content jqgrow ui-row-ltr ui-state-highlight" tabindex="0" role="row" aria-selected="true">
<td aria-describedby="jqLst_Short Name" style="text-align:left;" role="gridcell">
ttc202
</td>
<td aria-describedby="jqLst_Long Name" style="text-align:left;" role="gridcell">
Testing Training Company 202
</td>
<td aria-describedby="jqLst_Actions" title="" style="text-align:center;" role="gridcell">
<a class="act avw" title="View this Organisation" href="company/view?lcId=86"></a>
<a class="act aed" title="Edit this Organisation" href="company/edit?lcId=86"></a>
</td>
</tr>
I have tried this:
//td[contains(text(),'ttc202')]/following-sibling::td[contains(a/title(),'Edit this Organisation')]/a
All help appreciated. I assume I am missing something to skip over the first column, but can't imagine what will enable me to do that...
Progress:
I have found the following as an alternative which should get to the correct cell, but I am not able to workout how to target the title in the link code:
//td[normalize-space() ="ttc202"])[1]/following-sibling::td[2]/a[. = 'Edit']
I think this is progress just not sufficient to get me to the finish line!
After much investigation I found the following answer, perhaps this might help others who come across this question:
//tr[contains(td[1], "ttc202")]/td[3]/a[#title='Edit this Organisation']
The trick was realising which cell the information was in (represented by the square brackets).

MailChimp template: Nested repeatable variants?

I'm building a MailChimp template and would like to have nested repeatable variants. Something like this
-- Variant 1A
-- Variant 2A
-- Variant 2B
-- Variant 1B
-- Variant 3A
-- Variant 3B
-- Variant 1C
-- Variant 4A
-- Variant 4B
When I nest mc:repeatable="" and mc:variant="" elements inside another repeatable/variant tag it doesn't work. The inner repeatables don't appear in the editor. Removing the inner repeatable/variant tags makes the content appear again, but the ability to repeat the content blocks is lost obviously.
Here's a full example of the code:
<tr mc:repeatable>
<td>
<table>
<tr mc:repeatable="rating" mc:variant="variant1">
<td>
<div mc:edit="text">
</div>
</td>
</tr>
<tr mc:repeatable="rating" mc:variant="variant2">
<td>
<div mc:edit="text">
</div>
</td>
</tr>
</table>
</td>
</tr>
Has anyone been able to nest repeatable/variant blocks in a MailChimp template?
Looking at mc:repeatable in MailChimp's Reference apparently it is possible to nest repeatable elements within repeatable elements, though it's "not encouraged"
http://templates.mailchimp.com/getting-started/template-language/
I'm also trying to do something similar, from what I can tell, it doesn't seem possible to use a mc:variant inside a mc:repeatable and have it work the way we want.
Using the following:
<div mc:repeatable="repeat-wrapper">
<h1>Repeat wrapper</h1>
<tr>
<td>
<div mc:repeatable="catsdogsbirdsfish"
mc:variant="meow meow meow!">
<h1>Meow!</h1>
Cats are the best!
</div>
<div mc:repeatable="catsdogsbirdsfish"
mc:variant="woof woof woof!">
<h1>Woof!</h1>
Dogs are the best!
</div>
<div mc:repeatable="catsdogsbirdsfish"
mc:variant="tweet tweet tweet!">
<h1>Tweet!</h1>
Birds are the best!
</div>
<div mc:repeatable="catsdogsbirdsfish"
mc:variant="glub glub glub!">
<h1>Glub?</h1>
I don't know what sounds fish make,
but they are the best!
</div>
</td>
<td><p>End of the repeating element</p></td>
</tr>
</div>
I could create and repeat any number of Cats, Dogs, Birds or Fish. The repeating UI appeared along with the variant dropdown selector. I could also create a new Repeat Wrapper but I could not insert any Cats, Dogs or Birds inside the newly repeated container :/
You can't nest repeatable within repeatable
From MailChimp:
The mc:repeatable attribute defines a content block that can be
repeatedly added to the template. When using mc:repeatable, make sure
to use proper nesting of items. An mc:repeatable section should never
be contained within an mc:edit section. Instead, nest your mc:edit
sections within your mc:repeatable blocks. Never nest mc:repeatable
blocks within other mc:repeatable blocks, mc:edit areas within other
mc:edit areas, or mc:edit images within mc:edit areas.

colspan like feature for spring form textarea

How can I get colspan like feature in a form:textarea in spring form tag?
This is my current code:
<td><html:textarea rows="5" cols="60" path="comment" /></td>
There are total 5 columns in the table. I would like to have the label in the first column and textarea in the remaining 4 colums. How can I achieve this?
I think you don't need a "colspan-like" solution but colspan itself. Note that what you want to span is a table cell, not the textarea. Therefore, you must use the attribute on the enclosing td element.
Text areas in HTML have their own layout of rows and columns but it's completely unrelated to HTML tables. A colspan attribute on a textarea simply doesn't make sense.
Here's a piece of HTML code that does the trick.
<table>
<tr>
<td>X</td>
<td>Y</td>
<td>Z</td>
</tr>
<tr>
<td>label</td>
<td colspan="2"><textarea cols="60" rows="3"></textarea></td>
</tr>
</table>
Here's a working example on JSFiddle, styled with CSS to make the structure more visible.

Link to a line Markdown file on GitHub

I often link to GitHub source code via the #L param in the URI.
e.g. : https://github.com/github/learn.github.com/blob/gh-pages/episodes.yaml#L1
But is there a way to link to lines within a Markdown file?
e.g. https://github.com/github/learn.github.com/blob/gh-pages/README.md#L1 (does not work!)
I know I can link to 'sections', but lines are much better!
e.g. https://github.com/github/learn.github.com/blob/gh-pages/README.md#learngithubcom
As it is currently not possible, I take the next best option: use blame and then highlight the lines, e.g. https://github.com/rails/rails/blame/master/guides/source/configuring.md#L166
Now Supported with ?plain=1
Announced on June 30, 2021, there is now a parameter to disable markdown rendering:
Appending ?plain=1 to the url for any Markdown file will now display the file without rendering. As with other code files, it will also show line numbers, and can be used to link other users to a specific line or lines. For example, appending ?plain=1#L52 will highlight line 52 of a plain text Markdown file.
It sounded like you might want to use line numbers to link to a point in the rendered document. That is still possible, nor is it a standard feature of markdown renders to add line number anchors like that.
For the benefit of the reader: The long answer is yes, it is difficult, but possible.
GitHub allows to inline permalinks to the text portion of Markdown files
However there seems currently to be no way to create such permalinks directly, you must manually create them. As follows:
Display the markdown document
Above the document on the right click on the shortened SHA of the document
(you can use "History" and the commit in question as well)
The commit's diff is shown.
Above the commit on the right click on the the 3 dots ... and select "View file"
Now the Mardown is presented again however it is the permanent variant.
Above the document on the right click on "Blame"
Scroll down to the lines which contain the Markdown representation of the text to cite
Select the line or lines in question
Copy the URL from the address bar of the browser
Paste the URL into the issue etc.
This step is only needed within issues: In the URL replace /blame/ by /blob/
In the preview of the Issue you will see the expected direct citing of the text portion of the Markdown.
Drawback of the /blob/-variant
If you click on the URL, you see the full Markdown in the browser, the text portion is not marked as expected.
This is a limitation on how GitHub handles those URLs.
Drawback of the /blame/-variant
It is plain unreadable because of all those annotations and non-rendering of the Markdown.
Example
Note that I had to clone this example to be able to create an issue:
https://github.com/hilbix/learn.github.com/blob/gh-pages/README.md
Click on the SHA
https://github.com/hilbix/learn.github.com/commit/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba
"View File"
https://github.com/hilbix/learn.github.com/blob/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba/README.md
"Blame"
https://github.com/hilbix/learn.github.com/blame/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba/README.md
Mark some lines
https://github.com/hilbix/learn.github.com/blame/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba/README.md#L20-L23
Change the URL
https://github.com/github/learn.github.com/blob/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba/README.md#L20-L23
Paste this URL into some issue
Result: https://github.com/hilbix/learn.github.com/issues/1
This was entered into the issue:
https://github.com/hilbix/learn.github.com/blob/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba/README.md#L20-L23
see https://stackoverflow.com/a/57202063/490291
This renders to something like
learn.github.com/README.md
Lines 20 to 23 in 38034b3
$ git clone https://github.com/github/learn.github.com
$ cd learn.github.com
$ script/bootstrap
$ jekyll --server
see https://stackoverflow.com/a/57202063/490291
Here is the full HTML of the issue created (sorry, I did not manage to copy the CSS, too):
<td class="d-block comment-body markdown-body js-comment-body">
<p></p><div class="border rounded-1 my-2">
<div class="f6 px-3 py-2 lh-condensed border-bottom bg-gray-light">
<p class="mb-0 text-bold">
learn.github.com/README.md
</p>
<p class="mb-0 text-gray-light">
Lines 20 to 23
in
<a data-pjax="true" class="commit-tease-sha" href="/hilbix/learn.github.com/commit/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba">38034b3</a>
</p>
</div>
<div itemprop="text" class="blob-wrapper blob-wrapper-embedded data">
<table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8">
<tbody><tr class="border-0">
<td id="L20" class="blob-num border-0 px-3 py-0 bg-white js-line-number" data-line-number="20"></td>
<td id="LC20" class="blob-code border-0 px-3 py-0 bg-white blob-code-inner js-file-line"> <span class="pl-s1">$ git clone https://github.com/github/learn.github.com</span> </td>
</tr>
<tr class="border-0">
<td id="L21" class="blob-num border-0 px-3 py-0 bg-white js-line-number" data-line-number="21"></td>
<td id="LC21" class="blob-code border-0 px-3 py-0 bg-white blob-code-inner js-file-line"> <span class="pl-s1">$ <span class="pl-c1">cd</span> learn.github.com</span> </td>
</tr>
<tr class="border-0">
<td id="L22" class="blob-num border-0 px-3 py-0 bg-white js-line-number" data-line-number="22"></td>
<td id="LC22" class="blob-code border-0 px-3 py-0 bg-white blob-code-inner js-file-line"> <span class="pl-s1">$ script/bootstrap</span> </td>
</tr>
<tr class="border-0">
<td id="L23" class="blob-num border-0 px-3 py-0 bg-white js-line-number" data-line-number="23"></td>
<td id="LC23" class="blob-code border-0 px-3 py-0 bg-white blob-code-inner js-file-line"> <span class="pl-s1">$ jekyll --server</span> </td>
</tr>
</tbody></table>
</div>
</div>
<p></p>
<p>see <a rel="nofollow" href="https://stackoverflow.com/a/57202063/490291">https://stackoverflow.com/a/57202063/490291</a></p>
</td>
I recently looked for the same. Answer is No, as mentioned in other answers.
But I found a good alternative which gives almost the same result we want.
Adding text fragment to url.
For example: https://github.com/github/balanced-employee-ip-agreement#:~:text=FAQ
You just have to append #:~:text={text-that-you-want-to-be-focussed} at the end of the url
read more about text fragment here.
https://wicg.github.io/scroll-to-text-fragment/
Short answer: no. Markdown is rendered into an HTML document by GitHub, so it's not currently possible to see it in a raw form that also allows you to link to individual lines. Maybe GitHub will implement this kind of functionality sometime in the future, but for now, it's not possible.
There's now support for this in the UI
This just dropped: https://twitter.com/github/status/1443572280924147717
Click on README.md in the directory you're looking at
Its URL will look like this: https://github.com/rust-lang/rust/blob/master/README.md
Click the "Display the source blob" button:
The URL will change to https://github.com/rust-lang/rust/blob/master/README.md?plain=1, as described in this answer
You can now click on line numbers and obtain links to these lines
There's still no such button to do this for .rst files, but adding ?plain=1 to the URL works: https://github.com/python/cpython/blob/main/README.rst?plain=1
When you want to link to a line in a file controlled by you, you can use <a>: https://stackoverflow.com/a/6494918/5053865
Example:
<a name="your_link_name">
Some line which you want to link to
</a>
... some wall of text ...
and here you are able to link to [the line](#your_link_name)
Example on GitHub: https://github.com/evis/markdown-link-to-line (it's in readme file).
This way, you can't refer to a line with a given number, but can refer to a line with needed content (which is exactly what you often need).

Nesting dynamically displayed components in wicket

I have a need to create following kind of markup with wicket using ajax:
<table>
<tr>
<td><a>first</a></td>
<tr>
<tr>
<td>displayed/closed if first is clicked <a>open</a></td>
</tr>
<tr><td>this and following displayed/closed if above open is clicked</td></tr>
<tr><td>there may be any number of these</td></tr>
<tr>
<td>there may be any number of these as well <a>open</a></td>
</tr>
<tr>
<td>any number of these as well <a>second</a></td>
</tr>
</table>
How to use ListViews or some other wicket element to individually toggle open "inner" rows of the table. I don't want to resort to render everything and toggling visibility but really create the rows in server side only when expand is requested. The markup should also be valid xhtml (rules out arbitrary container for row groups). I know I can put multiple tbodys, but it's good enough only for one level of nesting (no .... allowed).
From Lord Torgamus' comment, the ajax tree sounds appropriate..