groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Format-agnostic hyperlinks


From: John Gardner
Subject: Re: Format-agnostic hyperlinks
Date: Fri, 24 Jul 2020 13:42:43 +1000

>
> albeit a bit mind warping to see Markdown and Troff mixed.


Heh, I wouldn't call that Markdown. Particularly when I'm going to add a
third syntax for email addresses:

.[ "This mailing list" ]< *groff@gnu.org <groff@gnu.org>* >
.[ *groff@gnu.org <groff@gnu.org>* ]<>


The reason for this third syntax is so "mailto:"; won't be printed in
non-interactive mediums, since this:

This mailing list <*groff@gnu.org <groff@gnu.org>*>


is more readable than this:

This mailing list (*mailto:groff@gnu.org <groff@gnu.org>*)


The URL can be literally anything, even relative links (e.g., "
./this-other-page.html")


Does your package interpret the URL that's passed in?


Nope, not at all. URLs are passed through verbatim; authors can always add
\: themselves, although toggling word-breakage is probably better achieved
using a "no-wrap" macro. This would benefit not just URLs, but also
command-line switches appearing in wrapped paragraphs:

I hate seeing `-o|-option-
names` broken across `-l|--

lines` like this.



Not many documents have been written using www.tmac


Heh, for good-reason. Groff's HTML output is somewhat... inside-out.  One
of these days I'll develop a modern alternative for proper HTML output, but
that's a project for another day (or year, more than likely...)


On Fri, 24 Jul 2020, 9:09 am B 9, <hackerb9@member.fsf.org> wrote:

> John Gardner <gardnerjohng@gmail.com> wrote:
>
> > Recent discussion on this list about PDF and HTML links galvanised an
> > earlier attempt of mine to implement hyperlinks in Troff in a device- and
> > package-agnostic manner: It's still very much a W.I.P., but
> >
> > .[ "here's what I've done so far" ](
> > https://github.com/Alhadis/Mono/commit/f363ed40d ) ,
>
> This looks pretty cool and useful, albeit a bit mind warping to see
> Markdown and Troff mixed.
>
> I am hopeful that the pdfmark upgrade I made to www.tmac will be
> included in groff and am still making tweaks to perfect it.
>
> Does your package interpret the URL that's passed in? One thing I'm
> still figuring out for www.tmac is whether the location provided to
> the .URL macro should be used verbatim or interpreted. Not many
> documents have been written using www.tmac, but it looks like early on
> the URL had to be interpreted to avoid URLs running off the right
> margin. Each user needed to specify all potential line breaks by hand.
> For example, this was necessary,
>
>     .URL "http://\:ftp.gnu.org/\:gnu/\:groff/
> <http://ftp.gnu.org/%5C:gnu/%5C:groff/>" "GNU host"
>
> At some point, www.tmac gained the ability to automatically break long
> URLs after slashes, so this awkward syntax isn't necessary, nor is
> interpreting the URL. I believe www.tmac should act similarly to
> Heirloom Troff's \W: the URL should not be interpreted. But, there may
> be hidden downsides I don't know of.
>
> How does your Mono handle wrapping URLs? Do authors have to add "\:"?
> What happens if an author tries to add a possible break point that way?
> Do you have (or intend to have) automatic line breaking for URLs?
>
> It would be nice if there was a single macro that could be the Groff
> default for proper URL wrapping which encapsulated all the clever tips
> people have posted to this list.
>
> Here's the algorithm currently used by www.tmac, which only works on
> slashes.
>
>     .
>     .\"
> --------------------------------------------------------------------
>     .\" www:url_breaks (<string_name>)
>     .\"
>     .\" Add '\:' (possible break point) within URL strings after '/'.
>     .\"
>     .\" Smart about multiple '/', existing '\:', and space characters;
>     .\" does not set a break point if less than 5 characters would go to
>     .\" the next line.
>     .\"
>     .de www:url_breaks
>     .  if !(\\n[.$] == 1) \
>     .    www:error .\\$0 expects 1 argument.
>     .  if !\n[www:substring_ok] \
>     .    return
>     .  ds \\$0:s "\\*[\\$1]\"
>     .  www:splitstr \\$0:s
>     .  www:url_breaks_split \\$0:s \\*[\\$0:s]
>     .  ds \\$1 "\\*[\\$0:s]\"
>     .  rm \\$0:s
>     ..
>     .
>     .\"
> --------------------------------------------------------------------
>     .\" www:url_breaks_split (<result> <char> [<char>...])
>     .\"
>     .\" Add '\:' within URL strings, but arguments are a split string.
>     .\"
>     .\" Arguments: >=2: <result> <char> [<char>...]
>     .\"
>     .de www:url_breaks_split
>     .  nr \\$0:min 5        \" minimal number of characters for next line
>     .  if (\\n[.$] < 2) \
>     .    www:error .\\$0 expects at least 2 arguments.
>     .  ds \\$0:res \\$1\"
>     .  shift
>     .  ds \\$0:s
>     .  nr \\$0:done 0
>     .  while !\\n[\\$0:done] \{\
>     .    if (\\n[.$] <= 0) \
>     .      break
>     .    if '\\$1'space' \{\
>     .      as \\$0:s " \"
>     .      shift
>     .      continue
>     .    \}
>     .    if (\\n[.$] < \\n[\\$0:min]) \{\
>     .      as \\$0:s "\\$1\"
>     .      shift
>     .      continue
>     .    \}
>     .    if !'\\$1'/' \{\
>     .      as \\$0:s "\\$1\"
>     .      shift
>     .      continue
>     .    \}
>     .    \" we are at a '/' character
>     .    while '\\$1'/' \{\
>     .      as \\$0:s /\"
>     .      if (\\n[.$] == 0) \{\
>     .        nr \\$0:done 1
>     .        break
>     .      \}
>     .      shift
>     .    \}
>     .    if \\n[\\$0:done] \
>     .      break
>     .    if (\\n[.$] < \\n[\\$0:min]) \
>     .      continue
>     .    if '\\$1'\:' \
>     .      shift
>     .    as \\$0:s \:\"
>     .  \}
>     .  ds \\*[\\$0:res] \\*[\\$0:s]\"
>     .  rm \\$0:res
>     .  rm \\$0:s
>     ..
>
> Ideally, the www:url_breaks macro would add in optional breaks after
> every symbol, except period, percent, and hyphen. Period and percent
> would have breaks added before the symbol.
>
> (Hyphens wouldn't be added at line breaks and breaks wouldn't happen
> after hyphens, to avoid confusion.)
>
> --b9
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]