GNUnet  0.20.0
typescriptdomain.LinkingHtmlFormatter Class Reference
Inheritance diagram for typescriptdomain.LinkingHtmlFormatter:
[legend]
Collaboration diagram for typescriptdomain.LinkingHtmlFormatter:
[legend]

Public Member Functions

def __init__ (self, **kwargs)
 

Private Member Functions

def _get_value (self, value, tok)
 
def _fmt (self, value, tok)
 
def _format_lines (self, tokensource)
 

Private Attributes

 _builder
 
 _bridge
 

Detailed Description

Definition at line 370 of file typescriptdomain.py.

Constructor & Destructor Documentation

◆ __init__()

def typescriptdomain.LinkingHtmlFormatter.__init__ (   self,
**  kwargs 
)

Definition at line 371 of file typescriptdomain.py.

371  def __init__(self, **kwargs):
372  super(LinkingHtmlFormatter, self).__init__(**kwargs)
373  self._builder = kwargs["_builder"]
374  self._bridge = kwargs["_bridge"]
375 

Member Function Documentation

◆ _get_value()

def typescriptdomain.LinkingHtmlFormatter._get_value (   self,
  value,
  tok 
)
private

Definition at line 376 of file typescriptdomain.py.

376  def _get_value(self, value, tok):
377  xref = tok_getprop(tok, "xref")
378  caption = tok_getprop(tok, "caption")
379 
380  if tok_getprop(tok, "is_literal"):
381  return '<span style="font-weight: bolder">%s</span>' % (value,)
382 
383  if tok_getprop(tok, "trailing_underscore"):
384  logger.warn(
385  "{}:{}: code block contains xref to '{}' with unsupported trailing underscore".format(
386  self._bridge.path, self._bridge.line, xref
387  )
388  )
389 
390  if tok_getprop(tok, "is_identifier"):
391  if xref.startswith('"'):
392  return value
393  if re.match("^[0-9]+$", xref) is not None:
394  return value
395  if xref in (
396  "number",
397  "object",
398  "string",
399  "boolean",
400  "any",
401  "true",
402  "false",
403  "null",
404  "undefined",
405  "Array",
406  "unknown",
407  ):
408  return value
409 
410  if self._bridge.docname is None:
411  return value
412  if xref is None:
413  return value
414  content = caption if caption is not None else value
415  ts = self._builder.env.get_domain("ts")
416  r1 = ts.objects.get(("type", xref), None)
417  if r1 is not None:
418  rel_uri = (
419  self._builder.get_relative_uri(self._bridge.docname, r1[0])
420  + "#"
421  + r1[1]
422  )
423  return (
424  '<a style="color:inherit;text-decoration:underline" href="%s">%s</a>'
425  % (rel_uri, content)
426  )
427 
428  std = self._builder.env.get_domain("std")
429  r2 = std.labels.get(xref.lower(), None)
430  if r2 is not None:
431  rel_uri = (
432  self._builder.get_relative_uri(self._bridge.docname, r2[0])
433  + "#"
434  + r2[1]
435  )
436  return (
437  '<a style="color:inherit;text-decoration:underline" href="%s">%s</a>'
438  % (rel_uri, content)
439  )
440  r3 = std.anonlabels.get(xref.lower(), None)
441  if r3 is not None:
442  rel_uri = (
443  self._builder.get_relative_uri(self._bridge.docname, r3[0])
444  + "#"
445  + r3[1]
446  )
447  return (
448  '<a style="color:inherit;text-decoration:underline" href="%s">%s</a>'
449  % (rel_uri, content)
450  )
451 
452  logger.warn(
453  "{}:{}: code block contains unresolved xref '{}'".format(
454  self._bridge.path, self._bridge.line, xref
455  )
456  )
457 
458  return value
459 
def tok_getprop(tok, key)

References typescriptdomain.LinkingHtmlFormatter._bridge, typescriptdomain.LinkingHtmlFormatter._builder, and typescriptdomain.tok_getprop().

Referenced by typescriptdomain.LinkingHtmlFormatter._fmt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _fmt()

def typescriptdomain.LinkingHtmlFormatter._fmt (   self,
  value,
  tok 
)
private

Definition at line 460 of file typescriptdomain.py.

460  def _fmt(self, value, tok):
461  cls = self._get_css_class(tok)
462  value = self._get_value(value, tok)
463  if cls is None or cls == "":
464  return value
465  return '<span class="%s">%s</span>' % (cls, value)
466 

References typescriptdomain.LinkingHtmlFormatter._get_value().

Referenced by typescriptdomain.LinkingHtmlFormatter._format_lines().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _format_lines()

def typescriptdomain.LinkingHtmlFormatter._format_lines (   self,
  tokensource 
)
private
Just format the tokens, without any wrapping tags.
Yield individual lines.

Definition at line 467 of file typescriptdomain.py.

467  def _format_lines(self, tokensource):
468  """
469  Just format the tokens, without any wrapping tags.
470  Yield individual lines.
471  """
472  lsep = self.lineseparator
473  escape_table = _escape_html_table
474 
475  line = ""
476  for ttype, value in tokensource:
477  link = get_annotation(ttype, "link")
478 
479  parts = value.translate(escape_table).split("\n")
480 
481  if len(parts) == 0:
482  # empty token, usually should not happen
483  pass
484  elif len(parts) == 1:
485  # no newline before or after token
486  line += self._fmt(parts[0], ttype)
487  else:
488  line += self._fmt(parts[0], ttype)
489  yield 1, line + lsep
490  for part in parts[1:-1]:
491  yield 1, self._fmt(part, ttype) + lsep
492  line = self._fmt(parts[-1], ttype)
493 
494  if line:
495  yield 1, line + lsep
496 
497 
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
def get_annotation(tok, key)

References typescriptdomain.LinkingHtmlFormatter._fmt(), typescriptdomain.get_annotation(), and len.

Here is the call graph for this function:

Field Documentation

◆ _builder

typescriptdomain.LinkingHtmlFormatter._builder
private

◆ _bridge

typescriptdomain.LinkingHtmlFormatter._bridge
private

The documentation for this class was generated from the following file: