[Tex/LaTex] How to make a fancy rule under a line of text in ConTeXt

contextrules

I've (mis)used LaTeX on and off for the past 10 years and am now trying out ConTeXt, mostly because it allows alignment to a baseline grid. I'd like to produce a rule (line) below some text such that the rule:

  • is some distance (1pt, let's say) below the baseline of the text (assume the text fits on one line),
  • is as wide as the text area (\textwidth), and
  • terminates on the right end with a small black square vertically centered on the rule.

In LaTeX, I can do something like this:

\documentclass{article}
\usepackage{calc}

\begin{document}
\makebox[0pt][l]{%
  \rule[-1pt]{\textwidth-4pt}{.4pt}%
  \rule[-2.6pt]{4pt}{4pt}
}%
This text sits on the fancy rule.
\end{document}

Which gives me this:

Text on a fancy rule

How can I do something similar in ConTeXt? I've tried overlays and \blackrule, but I don't know how to move a \blackrule vertically. I'm open to any solution whether it involves overlays and \blackrules or something else, but I would like the text to align to the baseline grid if possible.

Best Answer

There are many other ways to do this in ConTeXt, but a literal translation of your method will be the following:

\starttext

\dontleavehmode
\rlap{\lower 1pt \blackrule[width=\dimexpr\textwidth-4pt\relax, height=0.4pt]%
      \lower 2.6pt \blackrule[width=4pt, height=4pt]}%
This text sits on the fancy rule.


\stoptext

which gives

enter image description here