1

In a Node.js Express web app, I would like to include a link to some documentation in one of my views, and show the URL as the anchor text. Following Jade: Links inside a paragraph, I tried:

p See #[a(href="http://example.com/help/123") http://example.com/help/123]

However, that causes an error, "The end of the string was reached with no closing bracket found."

If I put quotes around the anchor text, it mostly works, but I end up with quotes visible in the HTML output, which I don't want.

p See #[a(href="http://example.com/help/123") "http://example.com/help/123"]

Is something about the unquoted URL messing up the evaluation of the stuff inside the brackets? If so, can I escape it somehow to prevent the problem?

Community
  • 1
  • 1
amacleod
  • 1,450
  • 2
  • 15
  • 23
  • 1
    Seems like a bug to me. I've narrowed it down to this not working either: `p #[p :/]`. So the string `:/` (colon forward-slash) inside a nested tag `#[]` causes the error. edit: opened an [issue on jade gh](https://github.com/jadejs/jade/issues/2144) – laggingreflex Oct 24 '15 at 10:25

1 Answers1

1

Use a variable:

-var helpurl="http://example.com/help/123"
p See #[a(href=helpurl) #{helpurl}]

The double slash in the URL itself is probably being interpreted as the start of a comment, and preventing the evaluator from reading the rest of the expression, including its closing bracket.

EDIT: From the issue kindly opened by @laggingreflex (https://github.com/jadejs/jade/issues/2144), It is actually the colon-slash sequence that is problematic prior to Jade 2.0.0. For those using earlier versions, the Jade author ForbesLindesay recommends using equals-sign evaluation of a literal string.

p See #[a(href="http://example.com/help/123")= "http://example.com/help/123"]
amacleod
  • 1,450
  • 2
  • 15
  • 23