White space issue in markdown

Hi Team,

When I use comma or dot after the URL in markdown

[text](url).
[text](url),

The output has space between the text and comma or dot,

like text . or text ,

Can some one help me.

I am unable to reproduce the problem.

This markdown:

[A link to Google](https:/google.com), followed by a comma and some text.

Produces this HTML:

<p><a href="https:/google.com">A link to Google</a>, followed by a comma and some text.</p>

This appears to be a difference between blackfriday (no space) vs goldmark (with space).

@pointyfar, did you confirm that? Asking so we can direct them to an appropriate issue queue. :slight_smile:

Edit: ignore this post.


Tested it, yes. Should have added the details:

foo.md:

testing [text](#url). and [text](#url), end
[markup]
  defaultMarkdownHandler = "goldmark"

yields:

<p>testing <a href="#url">text</a>
. and <a href="#url">text</a>
, end</p>

while

[markup]
  defaultMarkdownHandler = "blackfriday"

yields:

<p>testing <a href="#url">text</a>. and <a href="#url">text</a>, end</p>

@Rajasekar_Sundaram please open an issue on the Goldmark repo here: https://github.com/yuin/goldmark/

1 Like

I cannot reproduce this issue with Goldmark in:

Hugo Static Site Generator v0.69.2/extended linux/amd64 BuildDate: 2020-04-24T12:43:32Z.

The example shows a newline in the HTML after each link. Are you using a render-hook (layouts/_default/_markup/render-link.html)?

If yes, is there a newline at the end of the file?

1 Like

Thank you @pointyfar

When i use Goldmark, there is a space. With blackfriday, there is no space.

But, i have other site that use same theme, same goldmark settings which doesnt produce any space.

I dont know what i did on this site, even used settings of other site. But, nothing helped.

Hi @jmooring

Let me check this.

My apologies: yes I was using render hooks on my sandbox testing site @jmooring . :woman_facepalming:

@Rajasekar_Sundaram one more thing to check: if your text editor is automatically adding newlines (ie with prettify etc)

1 Like

Hi @jmooring @pointyfar

Thank you so much for your support.

Yes, the file had new line and I used Atom editor (default editor for all my work) to remove the line. But, the editor kept creating a new line.

So, use notepadd ++ to remove the line and that worked. Now, there is no space between the link and dot or comma.

My be i need to check the editor setting to see why it is creating the new line every time.

Should a text file end with a newline, or not? At first glance this may seem like a tabs vs. spaces discussion, but the POSIX standard provides the following definitions:

  • Text File: A file that contains characters organized into zero or more lines.

  • Line: A sequence of zero or more non-newline characters plus a terminating newline character.

By definition, a text file without a newline has zero lines. It seems to me that every text file with content should have at least one line, which means it needs to end with a newline.

So, keep your editor configured as it is, and add this to the end of layouts/_default/_markup/render-link.html:

{{- /* This comment removes trailing newlines. */ -}}

Here’s a screen capture of my editor:

image

You are not the first to encounter this behavior, nor will you be the last. See:

As these issues have been closed without action (implicitly “as designed”), I am disinclined to create a new issue.

2 Likes

Just to add an extra example with square brackets instead of points and commas.

Markdown:

OpenAdmin [by [dmw0ng](https://www.hackthebox.eu/home/users/profile/82600)]  
IP: 10.10.10.171  
OS: Linux  
Difficulty: Easy  
Release: 4 Jan 2020  
Retired: 4 May 2020

HTML:

image

Note that the closing square bracket is on a new line, causing a whitespace in the rendered HTML.

view:source shows that most of the HTML is in long continuous lines, but breaks after the link.

[...]<h2 id=machine-info>Machine info</h2><p>OpenAdmin [by <a href=https://www.hackthebox.eu/home/users/profile/82600 target=_blank>dmw0ng</a>
]<br>IP: 10.10.10.171<br>OS: Linux<br>Difficulty: Easy<br>Release: 4 Jan 2020<br>Retired: 4 May 2020</p><h2 id=recon>Recon</h2>[...]

That was my problem – thank you :slight_smile: