Here are the examples of the python api flask.Markup taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
159 Examples
5
Source : app.py
with GNU Affero General Public License v3.0
from Vesihiisi
with GNU Affero General Public License v3.0
from Vesihiisi
def form_attributes(name: str) -> flask.Markup:
return (flask.Markup(r' id="') +
flask.Markup.escape(name) +
flask.Markup(r'" name="') +
flask.Markup.escape(name) +
flask.Markup(r'" ') +
form_value(name))
@app.template_filter()
5
Source : app.py
with GNU Affero General Public License v3.0
from Vesihiisi
with GNU Affero General Public License v3.0
from Vesihiisi
def user_link(user_name: str) -> flask.Markup:
user_href = 'https://www.wikidata.org/wiki/User:'
return (flask.Markup(r' < a href="' + user_href) +
flask.Markup.escape(user_name.replace(' ', '_')) +
flask.Markup(r'">') +
flask.Markup(r' < bdi>') +
flask.Markup.escape(user_name) +
flask.Markup(r' < /bdi>') +
flask.Markup(r' < /a>'))
@app.template_global()
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def dag_link(v, c, m, p):
if m.dag_id is None:
return Markup()
dag_id = bleach.clean(m.dag_id)
url = url_for(
'airflow.graph',
dag_id=dag_id,
execution_date=m.execution_date)
return Markup(
' < a href="{}">{} < /a>'.format(url, dag_id))
def log_url_formatter(v, c, m, p):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def dag_run_link(v, c, m, p):
dag_id = bleach.clean(m.dag_id)
url = url_for(
'airflow.graph',
dag_id=m.dag_id,
run_id=m.run_id,
execution_date=m.execution_date)
return Markup(' < a href="{url}">{m.run_id} < /a>'.format(**locals()))
def task_instance_link(v, c, m, p):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def state_token(state):
color = State.color(state)
return Markup(
' < span class="label" style="background-color:{color};">'
'{state} < /span>'.format(**locals()))
def parse_datetime_f(value):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def datetime_f(v, c, m, p):
attr = getattr(m, p)
dttm = attr.isoformat() if attr else ''
if timezone.utcnow().isoformat()[:4] == dttm[:4]:
dttm = dttm[5:]
return Markup(" < nobr>{} < /nobr>".format(dttm))
def nobr_f(v, c, m, p):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def label_link(v, c, m, p):
try:
default_params = ast.literal_eval(m.default_params)
except:
default_params = {}
url = url_for(
'airflow.chart', chart_id=m.id, iteration_no=m.iteration_no,
**default_params)
return Markup(" < a href='{url}'>{m.label} < /a>".format(**locals()))
def pool_link(v, c, m, p):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def pool_link(v, c, m, p):
url = '/admin/taskinstance/?flt1_pool_equals=' + m.pool
return Markup(" < a href='{url}'>{m.pool} < /a>".format(**locals()))
def pygment_html_render(s, lexer=lexers.TextLexer):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def fused_slots(v, c, m, p):
url = (
'/admin/taskinstance/' +
'?flt1_pool_equals=' + m.pool +
'&flt2_state_equals=running')
return Markup(" < a href='{0}'>{1} < /a>".format(url, m.used_slots()))
def fqueued_slots(v, c, m, p):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def fqueued_slots(v, c, m, p):
url = (
'/admin/taskinstance/' +
'?flt1_pool_equals=' + m.pool +
'&flt2_state_equals=queued&sort=10&desc=1')
return Markup(" < a href='{0}'>{1} < /a>".format(url, m.queued_slots()))
def recurse_tasks(tasks, task_ids, dag_ids, task_id_to_dag):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def hidden_field_formatter(view, context, model, name):
if wwwutils.should_hide_value_for_key(model.key):
return Markup('*' * 8)
val = getattr(model, name)
if val:
return val
else:
return Markup(' < span class="label label-danger">Invalid < /span>')
form_columns = (
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def dag_link(v, c, m, p):
url = url_for(
'airflow.graph',
dag_id=m.dag_id)
return Markup(
' < a href="{url}">{m.dag_id} < /a>'.format(**locals()))
def log_url_formatter(v, c, m, p):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def state_token(state):
color = State.color(state)
return Markup(
' < span class="label" style="background-color:{color};">'
'{state} < /span>'.format(**locals()))
def state_f(v, c, m, p):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def datetime_f(v, c, m, p):
attr = getattr(m, p)
dttm = attr.isoformat() if attr else ''
if datetime.now().isoformat()[:4] == dttm[:4]:
dttm = dttm[5:]
return Markup(" < nobr>{} < /nobr>".format(dttm))
def nobr_f(v, c, m, p):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def fused_slots(v, c, m, p):
url = (
'/admin/taskinstance/' +
'?flt1_pool_equals=' + m.pool +
'&flt2_state_equals=running')
return Markup(" < a href='{0}'>{1} < /a>".format(url, m.used_slots()))
def fqueued_slots(v, c, m, p):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def fqueued_slots(v, c, m, p):
url = (
'/admin/taskinstance/' +
'?flt1_pool_equals=' + m.pool +
'&flt2_state_equals=queued&sort=10&desc=1')
return Markup(" < a href='{0}'>{1} < /a>".format(url, m.queued_slots()))
def recurse_tasks(tasks, task_ids, dag_ids, task_id_to_dag):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def hidden_field_formatter(view, context, model, name):
if should_hide_value_for_key(model.key):
return Markup('*' * 8)
return getattr(model, name)
form_columns = (
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def dag_link(v, c, m, p):
dag_id = bleach.clean(m.dag_id)
url = url_for(
'airflow.graph',
dag_id=dag_id)
return Markup(
' < a href="{}">{} < /a>'.format(url, dag_id))
def log_url_formatter(v, c, m, p):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def datetime_f(v, c, m, p):
attr = getattr(m, p)
dttm = attr.isoformat() if attr else ''
if datetime.utcnow().isoformat()[:4] == dttm[:4]:
dttm = dttm[5:]
return Markup(" < nobr>{} < /nobr>".format(dttm))
def nobr_f(v, c, m, p):
3
Source : views.py
with Apache License 2.0
from abhioncbr
with Apache License 2.0
from abhioncbr
def hidden_field_formatter(view, context, model, name):
if wwwutils.should_hide_value_for_key(model.key):
return Markup('*' * 8)
try:
return getattr(model, name)
except AirflowException:
return Markup(' < span class="label label-danger">Invalid < /span>')
form_columns = (
3
Source : service.py
with MIT License
from cds-snc
with MIT License
from cds-snc
def default_letter_contact_block_html(self):
if self.default_letter_contact_block:
return Markup(
Take(
Field(
self.default_letter_contact_block["contact_block"],
html="escape",
)
).then(nl2br)
)
return ""
def edit_letter_contact_block(self, id, contact_block, is_default):
3
Source : routes.py
with MIT License
from certanet
with MIT License
from certanet
def getting_started(profile, node):
if not profile:
new_link = url_for('new_model', slug='connectionprofiles')
message = Markup("Looks like you haven't created a Connection Profile! Click < a href=\"{}\">here < /a> to get started...".format(new_link))
elif not node:
new_link = url_for('new_model', slug='nodes')
message = Markup("Nearly there, but you haven't created any Nodes! Click < a href=\"{}\">here < /a> to get started...".format(new_link))
result = [message, 'warning']
flash(*result)
@app.route('/')
3
Source : views.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def pre_delete(self, item: BaseDatasource) -> None:
if item.slices:
raise SupersetException(
Markup(
"Cannot delete a datasource that has slices attached to it."
"Here's the list of associated charts: "
+ "".join([i.slice_name for i in item.slices])
)
)
3
Source : models.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def datasource_link(self) -> str:
url = f"/superset/explore/{self.type}/{self.id}/"
name = escape(self.datasource_name)
return Markup(f' < a href="{url}">{name} < /a>')
def get_metric_obj(self, metric_name: str) -> Dict[str, Any]:
3
Source : models.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def link(self) -> Markup:
name = escape(self.name)
anchor = f' < a target="_blank" href="{self.explore_url}">{name} < /a>'
return Markup(anchor)
def get_schema_perm(self) -> Optional[str]:
3
Source : helpers.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def _user_link(user: User) -> Union[Markup, str]: # pylint: disable=no-self-use
if not user:
return ""
url = "/superset/profile/{}/".format(user.username)
return Markup(' < a href="{}">{} < /a>'.format(url, escape(user) or ""))
class AuditMixinNullable(AuditMixin):
3
Source : sql_lab.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def pop_tab_link(self) -> Markup:
return Markup(
f"""
< a href="/superset/sqllab?savedQueryId={self.id}">
< i class="fa fa-link"> < /i>
< /a>
"""
)
@property
3
Source : mixins.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def pre_delete(self, database: Database) -> None: # pylint: disable=no-self-use
if database.tables:
raise SupersetException(
Markup(
"Cannot delete a database that has tables attached. "
"Here's the list of associated tables: "
+ ", ".join("{}".format(table) for table in database.tables)
)
)
def check_extra(self, database: Database) -> None: # pylint: disable=no-self-use
3
Source : get_a_guid.py
with MIT License
from derekmerck
with MIT License
from derekmerck
def info():
content = read(os.path.dirname(__file__), 'README.md')
content = content + "\n\n" + "Mint version: {0} | API version: {1}".format(mint_version, api_version)
content = Markup(markdown.markdown(content, ['markdown.extensions.extra']))
return render_template('index.html', **locals())
if __name__ == '__main__':
3
Source : trialist.py
with MIT License
from derekmerck
with MIT License
from derekmerck
def render_md(content, template='strapdown.html.j2', **kwargs):
title = config['title']
content = Markup(markdown.markdown(content, extensions=['markdown.extensions.extra']))
vars = locals()
vars.update(kwargs)
return render_template(template, **vars)
@app.route('/')
3
Source : widgets.py
with MIT License
from dhina016
with MIT License
from dhina016
def recaptcha_html(self, public_key):
html = current_app.config.get('RECAPTCHA_HTML')
if html:
return Markup(html)
params = current_app.config.get('RECAPTCHA_PARAMETERS')
script = RECAPTCHA_SCRIPT
if params:
script += u'?' + url_encode(params)
attrs = current_app.config.get('RECAPTCHA_DATA_ATTRS', {})
attrs['sitekey'] = public_key
snippet = u' '.join([u'data-%s="%s"' % (k, attrs[k]) for k in attrs])
return Markup(RECAPTCHA_TEMPLATE % (script, snippet))
def __call__(self, field, error=None, **kwargs):
3
Source : views.py
with MIT License
from dssg
with MIT License
from dssg
def report(dirname, name, reportid):
report_path = os.path.join(tempfile.gettempdir(), dirname, reportid)
if not os.path.exists(report_path):
abort(404)
with open(report_path) as fd:
report = fd.read()
return render_template(
'report.html',
content=Markup(report),
go_back=url_for('audit_file', dirname=dirname, name=name),
)
@app.route('/example.html', methods=['GET'])
3
Source : utils.py
with Apache License 2.0
from flink-extended
with Apache License 2.0
from flink-extended
def render(obj, lexer):
"""Render a given Python object with a given Pygments lexer"""
out = ""
if isinstance(obj, str):
out = Markup(pygment_html_render(obj, lexer))
elif isinstance(obj, (tuple, list)):
for i, text_to_render in enumerate(obj):
out += Markup(" < div>List item #{} < /div>").format(i) # noqa
out += Markup(" < div>" + pygment_html_render(text_to_render, lexer) + " < /div>")
elif isinstance(obj, dict):
for k, v in obj.items():
out += Markup(' < div>Dict item "{}" < /div>').format(k) # noqa
out += Markup(" < div>" + pygment_html_render(v, lexer) + " < /div>")
return out
def wrapped_markdown(s, css_class=None):
3
Source : utils.py
with Apache License 2.0
from flink-extended
with Apache License 2.0
from flink-extended
def wrapped_markdown(s, css_class=None):
"""Convert a Markdown string to HTML."""
if s is None:
return None
return Markup(f' < div class="{css_class}" >' + markdown.markdown(s) + " < /div>")
# pylint: disable=no-member
def get_attr_renderer():
3
Source : views.py
with GNU General Public License v3.0
from genotoul-bioinfo
with GNU General Public License v3.0
from genotoul-bioinfo
def documentation_result():
"""
Documentation result page
"""
with open(os.path.join(app_folder, "md", "user_manual.md"), "r",
encoding='utf-8') as install_instr:
content = install_instr.read()
md = Markdown(extensions=[TocExtension(baselevel=1)])
content = Markup(md.convert(content))
toc = Markup(md.toc)
return render_template("documentation.html", menu="documentation", content=content, toc=toc)
@app.route("/documentation/formats", methods=['GET'])
3
Source : views.py
with GNU General Public License v3.0
from genotoul-bioinfo
with GNU General Public License v3.0
from genotoul-bioinfo
def documentation_formats():
"""
Documentation formats page
"""
with open(os.path.join(app_folder, "md", "doc_formats.md"), "r",
encoding='utf-8') as install_instr:
content = install_instr.read()
md = Markdown(extensions=[TocExtension(baselevel=1), TableExtension()])
content = Markup(md.convert(content))
toc = Markup(md.toc)
return render_template("documentation.html", menu="documentation", content=content, toc=toc)
@app.route("/documentation/dotplot", methods=['GET'])
3
Source : views.py
with GNU General Public License v3.0
from genotoul-bioinfo
with GNU General Public License v3.0
from genotoul-bioinfo
def documentation_dotplot():
"""
Documentation dotplot page
"""
with open(os.path.join(app_folder, "md", "doc_dotplot.md"), "r",
encoding='utf-8') as install_instr:
content = install_instr.read()
md = Markdown(extensions=[TocExtension(baselevel=1)])
content = Markup(md.convert(content))
toc = Markup(md.toc)
return render_template("documentation.html", menu="documentation", content=content, toc=toc)
@app.route("/install", methods=['GET'])
3
Source : views.py
with GNU General Public License v3.0
from genotoul-bioinfo
with GNU General Public License v3.0
from genotoul-bioinfo
def install():
"""
Documentation: how to install? page
"""
latest = Latest()
with open(os.path.join(app_folder, "md", "INSTALL.md"), "r", encoding='utf-8') as install_instr:
content = install_instr.read()
env = Environment()
template = env.from_string(content)
content = template.render(version=latest.latest, win32=latest.win32)
md = Markdown(extensions=[TocExtension(baselevel=1)])
content = Markup(md.convert(content))
toc = Markup(md.toc)
return render_template("documentation.html", menu="install", content=content, toc=toc)
@app.route("/contact", methods=['GET'])
3
Source : views.py
with GNU General Public License v3.0
from genotoul-bioinfo
with GNU General Public License v3.0
from genotoul-bioinfo
def legal(page):
"""
Display legal things
"""
if page not in config_reader.legal:
abort(404)
with open(config_reader.legal[page], "r", encoding='utf-8') as md_page:
content = md_page.read()
env = Environment()
template = env.from_string(content)
content = template.render()
md = Markdown(extensions=['extra', 'toc'])
content = Markup(md.convert(content))
return render_template("simple.html", menu="legal", content=content)
@app.route("/paf/ < id_res>", methods=['GET'])
3
Source : text_display.py
with BSD 3-Clause "New" or "Revised" License
from glotzerlab
with BSD 3-Clause "New" or "Revised" License
from glotzerlab
def get_cards(self, job):
msg = self.message(job)
if self.markdown:
if MARKDOWN:
msg = Markup(
markdown.markdown(msg, extensions=["markdown.extensions.attr_list"])
)
else:
msg = "Error: Install the 'markdown' library to render Markdown."
return [{"name": self.name, "content": render_template(self.template, msg=msg)}]
3
Source : __init__.py
with MIT License
from jakewright
with MIT License
from jakewright
def index():
"""Present some documentation."""
# Open the README file
with open(os.path.dirname(app.root_path) + '/README.md', 'r') as markdown_file:
# Read the markdown contents
content = markdown_file.read()
# Convert the markdown to HTML and then treat it as actual HTML so it's not escaped
html = Markup(markdown.markdown(content, extensions=['markdown.extensions.fenced_code']))
return render_template('index.html', content=html)
class DeviceList(Resource):
3
Source : explorer.py
with GNU General Public License v3.0
from kudelskisecurity
with GNU General Public License v3.0
from kudelskisecurity
def post_webwallet_generate():
"""Create a new wallet - endpoint."""
wallet_name = WEBWALLET.generate_wallet()
flash(Markup(
f"Successfully generated new wallet < strong>{wallet_name} < /strong>. Please select it as the active wallet before use."),
FLASH_SUCCESS)
return redirect("/webwallet")
@app.route("/webwallet/select", methods=["POST"])
3
Source : explorer.py
with GNU General Public License v3.0
from kudelskisecurity
with GNU General Public License v3.0
from kudelskisecurity
def post_webwallet_select_wallet():
"""Select wallet - endpoint"""
wallet = request.form["wallet"]
success = WEBWALLET.set_active_wallet(wallet)
if success:
flash(Markup(f"Successfully changed active wallet to < span class=\"badge badge-dark\">{wallet} < /span>."),
FLASH_SUCCESS)
else:
flash(f"Failed to change active wallet.", FLASH_ERROR)
return redirect("/webwallet")
@app.route("/webwallet/tx", methods=["POST"])
3
Source : api.py
with GNU General Public License v3.0
from m8r0wn
with GNU General Public License v3.0
from m8r0wn
def api_clear():
## Clear pending commands
con = db_connect()
clear_pending(con)
con.close()
return render_template('admin.html', data=Markup(get_help()))
@APIRoutes.route('/api/master_log', methods=['GET'])
3
Source : flask.py
with Mozilla Public License 2.0
from MCArchive
with Mozilla Public License 2.0
from MCArchive
def safe_markdown(md):
"""
This filter renders the input as markdown nd then cleans the output with bleach.
Output will be HTML with only safe, white-listed tags.
"""
return Markup(bleach.clean(markdown(md),
tags=BLEACH_WHITELIST))
def register_filters(app):
3
Source : markdown.py
with GNU Affero General Public License v3.0
from minetest
with GNU Affero General Public License v3.0
from minetest
def init_markdown(app):
global md
md = Markdown(extensions=MARKDOWN_EXTENSIONS,
extension_configs=MARKDOWN_EXTENSION_CONFIG,
output_format="html5")
@app.template_filter()
def markdown(source):
return Markup(render_markdown(source))
def get_headings(html: str):
3
Source : webview.py
with Apache License 2.0
from patarapolw
with Apache License 2.0
from patarapolw
def execute():
if request.method == 'POST':
data = request.form
tags = data['tags'].strip().split(' ')
if data['type'] == 'vocab':
html = contents.print_vocabs(tags)
elif data['type'] == 'hanzi':
html = contents.print_hanzi(tags)
else:
html = contents.print_sentences(tags)
else:
html = ''
return render_template('index.html', content=Markup(html))
@app.route("/speak", methods=['POST'])
3
Source : category.py
with MIT License
from PlaidWeb
with MIT License
from PlaidWeb
def description(self) -> typing.Callable[..., str]:
""" Get the textual description of the category """
def _description(**kwargs) -> str:
if self._meta:
return flask.Markup(markdown.to_html(self._meta.get_payload(),
args=kwargs,
search_path=self.search_path,
counter=markdown.ItemCounter()))
return ''
if self._meta and self._meta.get_payload():
return utils.TrueCallableProxy(_description)
return utils.CallableValue('')
@cached_property
3
Source : entry.py
with MIT License
from PlaidWeb
with MIT License
from PlaidWeb
def _get_footnotes(self, body, more, args) -> str:
""" get the rendered Markdown footnotes for the entry """
footnotes: typing.List[str] = []
counter = markdown.ItemCounter()
if body and self._get_counter('body', args).footnote:
self._get_markup(body, True, args=args,
footnote_buffer=footnotes,
postprocess=False,
counter=counter)
if more and self._get_counter('more', args).footnote:
self._get_markup(more, True, args=args,
footnote_buffer=footnotes,
counter=counter)
if footnotes:
return flask.Markup(f" < ol>{''.join(footnotes)} < /ol>")
return ''
def _get_toc(self, body, more, max_depth, args) -> str:
3
Source : entry.py
with MIT License
from PlaidWeb
with MIT License
from PlaidWeb
def _get_toc(self, body, more, max_depth, args) -> str:
""" get the rendered ToC for the entry """
tocs: markdown.TocBuffer = []
args = {**args, '_suppress_footnotes': True}
counter = markdown.ItemCounter()
if body and self._get_counter('body', args).toc:
self._get_markup(body, True, args=args, toc_buffer=tocs, postprocess=False,
counter=counter)
if more and self._get_counter('more', args).toc:
self._get_markup(more, True, args=args, toc_buffer=tocs, counter=counter)
if tocs:
return flask.Markup(markdown.toc_to_html(tocs, max_depth))
return ''
def _get_counter(self, section, args) -> markdown.ItemCounter:
See More Examples