Hello everyone!
Here to discuss some code macro improvements ^^
A new user migrating from Confluence remarked that:
- the macro doesn’t have a copy button attached to it (issue link)
- the title of the code snippet isn’t by default stylized differently than the content itself (issue link).
Our code macro
- the title can be edited like any other text, but the spacing between the title and code can’t be achieved truly just by entering a new line (also, that would mean effort from the user)
- the language is not specified in view mode
- no copy button
- no configurability icon (that could help in discovering/remembering how to configure the macro)
Code macros in other places
Notion
- special button in the top-right with icon and label
- no title field
- caption button for giving more context (this could be used to give a title to the code snippet)
- more options button
Obsidian
People really wanted a copy button and someone did a plugin for it.
A plugin was done for adding titles to code blocks:
Confluence
- no title field
- copy button in separate toolbar
Proposal
Better format and add CSS classes to the code related to the macro to enable the styling changes. Currently, I’m not sure if we can style independently the title of the macro (let me know if I’m missing something).
The idea would be to have:
- a button with a label and an icon for copying the content of the macro
- the language showcased
- the title bolded
Case 1: No title, language non specified
Case 2: Title, language specified
Case 3: No title, language specified
Responsive mode
Might need to work on this a bit more. Can’t figure out a nice way of making the title be vertically centered (vertical-align: middle doesn’t work), but probably will.
Code
HTML
I think I may have not used icons the way I’m supposed to, looking for an practical example of doing this. Also, I’d appreciate feedback on the structure and naming of classes.
<div class="box">
<div class="code-toolbar">
<div class="box-copy-button btn btn-default">
<span class="fa fa-clone"></span>
<span class="copy-label">Copy</span>
</div>
<div class="code-fields">
<div class="snippet-title">The beginning</div>
<div class="snippet-language">C++</div>
</div>
</div>
<div class="code"><div class="linenoswrapper"><div class="linenos"> ... </div></div></div>
</div>
CSS
I know I need to use theme variables, I will come back on this tomorrow. Apart from colors and font-weight is there something in the following snippet that I should have not hard-coded?
.snippet-title {
display: inline;
font-weight: 600;
margin-right: 7px;
}
.box-copy-button {
display: inline;
float: right;
}
.copy-label {
display: inline;
margin-left: 2px;
}
.code-fields {
margin-top: -8px;
margin-bottom: 15px;
}
.snippet-language {
display: inline;
color: #777777
}
Copy Button Implementation
I was thinking we could reuse code from the copy button in the Information Tab (copy the refference of the current page).
Copy Button Macro Idea
It would be great if in addition we’d have a copy button macro that can be placed anywhere in a box, table, table cell. There are many instances where a user may want to allow themselves or others to easily copy a certain content (because of its often use).
Of course, this would need more thought in design, structure and more complex implementation.
What do you think about the proposal and the idea of the copy macro?