Typographic transforms (---, quote pairs, ~) no longer touch verbatim text: @c/@code/@source_listing content and ^'...'^ spans show exactly the characters written. "^" before any punctuation character quotes it in every target (the apostrophe excepted: ^' opens a literal span), with the new :resolve option on @@@target declaring per-target renderings. The ^UUUU^ code-point form accepts 4-6 hex digits, the full Unicode range. The html output and transform spellings are polyglot (XML-valid), in preparation for an EPUB target. New suites: transform_test, character_test (engine), typography_test (SKS). (from dev 07ce5ea86a0a)
28 lines
1006 B
Python
28 lines
1006 B
Python
import re
|
|
import klammer_base
|
|
import kutil
|
|
|
|
class Color(klammer_base.Klammer_base):
|
|
def __init__(self, K):
|
|
# kutil.msg()
|
|
super().__init__(K)
|
|
match = re.compile(r'([0-9.]+)\s*,\s*([0-9.]+)\s*,\s*([0-9.]+)', re.S).match(self.rgb)
|
|
if not match:
|
|
raise Exception(
|
|
'Error in color format: "{}". '.format(K.rgb)
|
|
+ 'Should be "<r>,<g>,<b>", where the components are [0,1].')
|
|
self.r, self.g, self.b = [float(c) for c in match.groups()]
|
|
|
|
def html(self):
|
|
result = 'rgb({},{},{})'.format(*[int(round(float(e*255))) for e in [self.r, self.g, self.b]])
|
|
#result = f"rgb({self.r},{self.g},{self.b}"
|
|
if self.text:
|
|
result = f'<span style="color:{result}">{self.text}</span>'
|
|
return result
|
|
|
|
def tex(self):
|
|
result = '\\color[rgb]{{{},{},{}}}'.format(self.r, self.g, self.b)
|
|
if self.text:
|
|
result = '{{{} {}}}'.format(result, self.text)
|
|
return result
|