Code block annotations #6546
-
Hi! We have a request from docsmobile to build a code block that supports annotations. AsciidocWe need to replace the annotation functionality in asciidoc (they call it code callouts, but functionally they are annotations). The existing asciidoc notation and UI is the following: [source,js]
-----
let happy = false <1>
const donut = 1
if (donut > 1) happy = true <2>
console.log(`I am ${!happy && 'not '}happy`)
-----
<1> By default, `happy` is set to `false`.
<2> But, if you have at least one https://www.doritedonuts.com/[`donut`] a day, set `happy` to `true`. RequirementsAt a minimum, we need a way to:
As far as "variables" for the notes, we have no need to support anything fancier than just numbers (i.e. ProposalI started looking into how we could implement this only because I wasn't sure if we would hack it or get you all to help (thanks for helping!). Here are my thoughts based on a little dig into code, you all are the EUI experts! ComponentEUI already has line-specific styling. It looks like this: I think we could write a partner to highlightByLine that instead of adding line styling, it adds a notification badge that we'll treat as the annotation footnote number. Then there would be a new partner component called EuiCodeNotes that lists all the notification badges (as footnotes) and the annotation it should accompany. I don't think this component should be exposed. The main new thing would be a wrapper of the two: EuiAnnotatedCode or something. It would take an array of tuples (or object, whatever) that would include the line number paired with the note. It would then pass the list of line numbers to annotate to the EUI Code Block and the list of notes to the EuiCodeNotes component. Additional contextFor the original request and any other notes that you might find interesting, see our issue: https://github.com/elastic/docsmobile/issues/337. It's worth noting that part of the request is to be able to go from MDX -> this component. That means figuring out what our MDX syntax should/could be and maybe writing a remark parser. I see that as something in our court but if that's an interesting thing for EUI, I'm open to talking about that! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 19 replies
-
[Just a suggestion/starting a brainstorming thread] Rather than footnotes, what are your thoughts a beacon + popover trigger of some sort over the line number? (Codepen link with source) I was using I suggest this approach because:
Thoughts? @miukimiu @daveyholler |
Beta Was this translation helpful? Give feedback.
-
Hi @glitteringkatie, FYI we had a very similar discussion started by Gareth one year ago: #5609. I like @cee-chen suggestion but I found the beacon very distracting. In cases where we can have two or more beacons, the animations seems to me too much. We could of course disable the animation, but then the beacon wouldn't look clickable. So based on @cee-chen initial idea, we could introduce a new type of beacon for annotations with an "i" icon or maybe a "question mark". It could also accept numbers and be clickable. Right now the Also in #5609, Dave suggested the following. gULXwpUfVVyvf-eU.mp4But it my opinion the left content can take too much space and it only makes sense for long content. For small one.. Not sure. @cee-chen and @glitteringkatie, let me know your thoughts on these ideas. |
Beta Was this translation helpful? Give feedback.
-
PR with implementation and staging link: #6580 |
Beta Was this translation helpful? Give feedback.
PR with implementation and staging link: #6580