How to wrap text automatically in a Mermaid flowchart node? - css

Is there a way to set a max width for text within a Mermaid flowchart node, such that it automatically wraps?
For example - how would I get the first graph to look like the second graph, without painstakingly inserting manual line breaks:
<script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.14.0/mermaid.min.js"></script>
<div class="mermaid">
flowchart TD
A{Is it Friday midday UTC?} -- Yes --> B(Check out Daft Punk's new single 'Get Lucky' if you have the chance. Sound of the summer.)
A -- No --> C(Never mind then)
</div>
<h2>Desired output</h2>
<div class="mermaid">
flowchart TD
A{Is it Friday</br>midday UTC?} -- Yes --> B(Check out Daft Punk's new single</br>'Get Lucky' if you have the chance.</br>Sound of the summer.)
A -- No --> C(Never mind then)
</div>
I have a suspicion the solution will be a single line of CSS but I don't know what it is.

Related

Is it possible to pass class to binding attribute in Angular?

We have a solution based on a numeric field being set to 1 or 2 or displaying certain icons. It works.
<span *ngIf="config.icon"
[class.fas]="true"
[class.fa-plus]="icon===1"
[class.fa-minus]="icon===2"
class="indicator">
</span>
I sense what shortly, we'll have a whole bunch of such icons (about 15 different ones). The suggested solution is either to put in 15 lines of specific class assignments or to build a specialized component managing that.
I'm opposed to both but haven't got it working out when I tried and googling led to irrelevant hits. Possibly due to my incompetence recognized th egood stuff.
Is it possible to do something like one of the following pseudo code lines? How?
[class.fa-{{iconName}}]="true"
[class]="iconName"
edit
Based on the comments/answers, I got it working using the following.
<span *ngIf="config.icon"
[ngClass]='{ "fas": true, "fa-plus": true }'></span>
However, for some reason, I'm not getting anything using the syntax below.
<span *ngIf="config.icon"
[ngClass]="classes"></span>
...
classes: { "fas": true, "fa-plus": true };
What am I missing?
You can try something like this:
<span class= "indicator"
[class.fas]="true"
[ngClass]="'fa-' + iconName">
</span>
See working example at https://stackblitz.com/edit/angular-mgecjw

bokeh tabs does not clear for subsequent figure

I'm not sure I can provide enough context here but I think so.
I'm running a bokeh server to generate a few plots and in a Flask app put them on a page, like this
script1 = bokeh.embed.server_document(...)
script2 = bokeh.embed.server_document(...)
...
return render_template(..., script1=script1, script2=script2)
On the template each plot is wrapped in a div with line breaks, paragraph breaks, and so on:
<style>
.gap-20 {
width:100%;
display: block;
}
</style>
<p>
<h3>Anchors and their inferences</h3>
<br />
<div class="gap-20">
{{ script1 | safe }}
</div>
</p>
<p>
<h3>Reproduction of forward data</h3>
<br />
<div class="gap-20">
{{ script2 | safe }}
</div>
</p>
The plots that mess up layout on the page are those containing 'Panel' and 'Tabs'. Other plots are fine. See image for the problem.
The problem is: the plot using 'Tabs' does not clear, so that the capture of the next plot, "Reproduction of forward data", appears to the right of the figure on the active tab, just below the tab titles, although I have plenty of and before "Reproduction of forward data".
The code for 'script1' is like this on the Bokeh server side:
from bokeh.plotting import figure
from bokeh.models import Slider, Panel, Tabs
from bokeh.layouts import column
f1 = figure(...)
s1 = Slider(...)
fig1 = column(s1, f1)
f2 = figure(...)
s2 = Slider(...)
fig2 = column(s2, f2)
tab1 = Panel(child=fig1, ...)
tab2 = Panel(child=fig2, ...)
tabs = Tabs(tabs=[tab1, tab2])
doc.add_root(tabs)
A puzzling part is that this used to work a few weeks ago, back then 'tabs' is wrapped in 'column', like 'doc.add_root(column(tabs))'. Days ago I upgraded Bokeh to the latest 0.12.13, the issue above appeared. With or without 'column', the issue is the same. I'm not totally sure Bokeh upgrade is the cause but it's very likely so.
So the question is, what needs to be done around this 'Tabs' or 'Panel' to fix this problem? Thanks.
New findings: with Bokeh 0.12.10, with Tabs wrapped in row or column, that is,
doc.add_root(row(tabs))
or
doc.add_root(column(tabs))
things work as expected. The next plot comes cleanly below the first. If Tabs are passed to doc.add_root w/o row or column, the problem described in the post and shown in the picture occurs.
Now upgrade to Bokeh 0.12.11, w/o row or column around Tabs, same problem as shown in the original question post (and the same as with Bokeh 0.12.10). With row or column, things are messier:
The two figures seem to be vertically collapsed. This bug continues through the latest version, 0.12.13.

Is there a way to make a plugin display lines 'between' numbered lines in atom?

In the atom editor I'd like to be able to create notes 'in between' the lines of a file. I'm more than happy to do this via a plugin, but I'm wondering if someone more experienced in the API can confirm whether it's even possible before I dive in.
Basically, if I open a file with 10 lines, I want to be able to 'insert' new lines between some of them (which will be saved to another file), while still maintaining the line numbering of the original file. Eg:
1 Hello
2 World
. This is a note line saved in another file 'attached' to line 2
3 Foo
4 Etc
Think along the lines of inline comments on GitHub.
You can use block decorations to inject text between two lines:
A block decoration is a special kind of decoration that allows you to insert a DOM node before or after a certain line, and have it follow the line as the buffer changes. You can see it in action by running the snippet below in the DevTools:
var element = document.createElement('div')
element.textContent = 'Block decorations! 🐲'
var editor = atom.workspace.getActiveTextEditor()
var marker = editor.markScreenPosition([0, 0])
editor.decorateMarker(marker, {type: 'block', position: 'before', item: element})
In your case, you would be injecting text rather than GIFs, but you get the idea!

Color Cells in Rstudio

I have a dataframe that I've imported from a csv. In a free text section the following was included which caused the cell in Rstudio to highlight Red:
<P><FONT style="BACKGROUND-COLOR: #ff0000">SP#12. Notified 7/9. Ending 7/29.</FONT></P>
<P>boa bin 7-24-2014</P>
<P>This is an amendment to ALT252143. We are adding habitable basement square footage to Unit 1. </P>
<P><FONT style="BACKGROUND-COLOR: #ff0000">PAID NOMINAL FEE ONLY</FONT></P>
I know that the "BACKGROUND-COLOR: #ff0000"bit is what is causing this but I can't find exactly how to reproduce this. Any ideas? The class of the vector is character. I'm using the preview version of Rstudio, not sure if that will make a difference.

ReST strikethrough

Is it possible to strike text through in Restructured Text?
Something that for example renders as a <strike> tag when converted to HTML, like:
ReSTructuredText
I checked the docs better, as suggested by Ville Säävuori, and I decided to add the strikethrough like this:
.. role:: strike
:class: strike
In the document, this can be applied as follows:
:strike:`This text is crossed out`
Then in my css file I have an entry:
.strike {
text-decoration: line-through;
}
There is at least three ways of doing it:
.. role:: strike
An example of :strike:`strike through text`.
.. container:: strike
Here the full block of test is striked through.
An undecorated paragraph.
.. class:: strike
This paragraph too is is striked through.
.. admonition:: cancelled
:class: strike
I strike through cancelled text.
After applying rst2html you get:
<p>An example of <span class="strike">strike through text</span>.</p>
<div class="strike container">
Here the full block of test is striked through.</div>
<p>An undecorated paragraph.</p>
<p class="strike">This paragraph too is is striked through.</p>
<div class="strike admonition">
<p class="first admonition-title">cancelled</p>
<p class="last">I strike through cancelled text.</p>
You use them with a style
.strike {
text-decoration: line-through;
}
Here I have taken the admonition directive as example but any
directive that allow the :class: option would do.
As it generates a span the role directive is the only one that
allow to apply your style to a part of a paragraph.
It is redundant to add a class strike to a directive also named
strike, as suggest Gozzilli, because the directive name is the default
class for the html output.
I have checked these syntax both with rest2html and Sphinx. But
while everything works as expected with rest2html the class
directive fail with Sphinx. You have to replace it with
.. rst-class:: strike
This paragraph too is is striked through.
This is only stated in a small
footnote of Sphinx reSt Primer.
According to the official spec there is no directive for strikethrough markup in ReST.
However, if the environment allows for :raw: role or you are able to write your own roles, then you can write a custom plugin for it.
I found the other answers very helpful.
I am not very familiar with Sphinx but I am using it for a project. I too wanted the strike-through ability and have got it working based on the previous answers.
To be clear, I added my strikethrough role as gozzilli mentioned but I saved it inside my conf.py using the rst_prolog variable as discussed in the stack overflow thread here. This means that this role is available to all of your rest files.
I then extended the base html template as described above by creating layout.htmlwithin _templatesinside my source directory. The contents of this file are:
{% extends "!layout.html" %}
{% set css_files = css_files + ["_static/myStyle.css"] %}
This basically includes a custom css file to all your built default html docs.
Finally, in my _static directory within my source directory I included the file myStyle.css which contains:
.strike {
text-decoration: line-through;
}
Which the other answers have already provided.
I am merely writing this answer as it wasn't obvious to me with my limited Sphinx experience which files to edit.
Here's a Python definition of a del role, which works better than the accepted answer if you want to use the role in multiple pages of a Pelican blog or a Sphinx documentation project:
from docutils import nodes
from docutils.parsers.rst import roles
def deleted_role(_role, rawtext, text, _lineno, _inliner, options={}, _content=[]):
roles.set_classes(options)
options.setdefault('classes', []).append("del")
return [nodes.inline(rawtext, text, **options)], []
roles.register_canonical_role('del', deleted_role)
Even better would be to extend the HTML writer to produce a proper <del> tag, like this:
from docutils import nodes
from docutils.parsers.rst import roles
from docutils.writers._html_base import HTMLTranslator
class delnode(nodes.inline):
pass
def visit_delnode(self, node):
self.body.append(self.starttag(node, 'del', ''))
def depart_delnode(self, node):
self.body.append('</del>')
HTMLTranslator.visit_delnode = visit_delnode
HTMLTranslator.depart_delnode = depart_delnode
def deleted_role(_role, rawtext, text, _lineno, _inliner, options={}, _content=[]):
roles.set_classes(options)
return [delnode(rawtext, text, **options)], []
roles.register_canonical_role('del', deleted_role)
You can trivially adjust it to produce an <s>, of course.
Consider the user may have a different background, so here is no one solution that can be suitable for everyone.
1.Only one file
If you only use it only on one file. For example, you published a simple project to PyPI, and you may probably just only one README.rst file. The following may you want.
.. |ss| raw:: html
<strike>
.. |se| raw:: html
</strike>
single line
=============
|ss| abc\ |se|\defg
multiple line
=============
|ss|
line 1
line 2
|se|
789
you can copy and paste it on this website: https://livesphinx.herokuapp.com/
and will see the picture as the following:
It's simple, and you can on directly see the preview on some IDE, for example, PyCharm.
bellow is writing for the users of Sphinx
2.beginner of Sphinx
If you are a beginner of Sphinx. ( I mean maybe you want to use Sphinx to create a document, but Python is not familiar for you ) then try as following:
# conf.py
from pathlib import Path
html_static_path = ['_static', ]
html_css_files = ['css/user.define.css'] # If you want to control which HTML should contain it, you can put it on the HTML, which is very like the answer by #Gregory Kuhn.
with open(Path(__file__).parent / Path('_static/css/user.define.rst'), 'r') as f:
user_define_role = f.read()
rst_prolog = '\n'.join([ user_define_role + '\n',]) # will be included at the beginning of every source file that is read.
# rst_epilog = '\n'.join([ user_define_role + '\n',]) # it's ok if you put it on the end.
user.define.rst
.. role:: strike
user.define.css
.strike {text-decoration: line-through;}
With the rst_prolog, It can auto-add the role on each rst files, but if you change the content( that file, it contains a format that you define), then you must rebuild to make the render is correct.
3.Create roles
You can create an extension to achieve it.
# conf.py
extensions = ['_ext.rst_roles', ]
html_static_path = ['_static', ]
html_css_files = ['css/user.define.css']
# rst_roles.py
from sphinx.application import Sphinx
from docutils.parsers.rst import roles
from docutils import nodes
from docutils.parsers.rst.states import Inliner
def strike_role(role, rawtext, text, lineno, inliner: Inliner, options={}, content=[]):
your_css_strike_name = 'strike'
return nodes.inline(rawtext, text, **dict(classes=[your_css_strike_name])), []
def setup(app: Sphinx):
roles.register_canonical_role('my-strike', strike_role) # usage: :my-strike:`content ...`
The full architecture:
conf.py
_ext/
rst_roles.py
_static/
css/
user.define.css
about the rules, you can reference this link rst-roles
And I vary recommended you to see the docutils.parsers.rst.roles.py .
I wrote an extension for this.
Just pip install sphinxnotes-strike and use:
:strike:`text`
or
:del:`text`
to show strike text.
For more info: https://sphinx-notes.github.io/strike/
Since Docutils 0.17, the HTML5-writer uses <del> if a matching class value is found in inline, literal, or container elements:
.. role:: del
:del:`This text has been deleted`, here is the rest of the paragraph.
.. container:: del
This paragraph has been deleted.

Resources