Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amplificação nos valores de Font Face Symbol a serem convertidos no XML #63

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 179 additions & 43 deletions scielo_classic_website/spsxml/sps_xml_pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,55 +430,191 @@ def transform(self, data):
class XMLFontFaceSymbolPipe(plumber.Pipe):
# https://www.alanwood.net/demos/symbol.html
FONTFACESYMBOL = {
'&': {"char": "&"},
'[': {"char": "["},
']': {"char": "]"},
'´': {"char": "×"},
'¸': {"char": "÷"},
'<': {"char": "<"},
'>': {"char": ">"},
'±': {"char": "±"},
'×': {"char": "·"},
'÷': {"char": "¦"},
'¢': {"char": "′"},
'¤': {"char": "/"},
'°': {"char": "°"},
'·': {"char": "·"},
'¼': {"char": "…"},
'½': {"char": "⏐"},
'²': {"char": '"'},
'â': {"char": "®"},
'ä': {"char": "™"},
'ã': {"char": "©"},
'ç': {"char": "⎜"},
'ê': {"char": "⎢"},
'ï': {"char": "⎪"},
'Ó': {"char": "©"},
'Ò': {"char": "®"},
'Ô': {"char": "™"},
'ô': {"char": "⎮"},
'ú': {"char": "⎥"},
'Ù': {"char": "∧"},
'Û': {"char": "⇔"},
'Ü': {"char": "≤"},
'«': {"char": "↔"},
'»': {"char": "≈"},
'£': {"char": "≤"},
'¬': {"char": "←"},
'®': {"char": "→"},
'¾': {"char": "⎯"},
'³': {"char": "≥"},
'!': {"char": "!", "name": "Exclamation mark"},
'#': {"char": "#", "name": "Number sign"},
'%': {"char": "%", "name": "Percent sign"},
'&': {"char": "&", "name": "Ampersand"},
'(': {"char": "(", "name": "Left parenthesis"},
')': {"char": ")", "name": "Right parenthesis"},
'+': {"char": "+", "name": "Plus sign"},
',': {"char": ",", "name": "Comma"},
'.': {"char": ".", "name": "Full stop"},
'/': {"char": "/", "name": "Solidus"},
'0': {"char": "0", "name": "Digit zero"},
'1': {"char": "1", "name": "Digit one"},
'2': {"char": "2", "name": "Digit two"},
'3': {"char": "3", "name": "Digit three"},
'4': {"char": "4", "name": "Digit four"},
'5': {"char": "5", "name": "Digit five"},
'6': {"char": "6", "name": "Digit six"},
'7': {"char": "7", "name": "Digit seven"},
'8': {"char": "8", "name": "Digit eight"},
'9': {"char": "9", "name": "Digit nine"},
':': {"char": ":", "name": "Colon"},
';': {"char": ";", "name": "Semicolon"},
'<': {"char": "<", "name": "Less-than sign"},
'=': {"char": "=", "name": "Equals sign"},
'>': {"char": ">", "name": "Greater-than sign"},
'?': {"char": "?", "name": "Question mark"},
'[': {"char": "[", "name": "Left square bracket"},
']': {"char": "]", "name": "Right square bracket"},
'_': {"char": "_", "name": "Low line"},
'{': {"char": "{", "name": "Left curly bracket"},
'|': {"char": "|", "name": "Vertical line"},
'}': {"char": "}", "name": "Right curly bracket"},
'A': {"char": "Α", "name": "Greek capital letter alpha"},
'B': {"char": "Β", "name": "Greek capital letter beta"},
'G': {"char": "Γ", "name": "Greek capital letter gamma"},
'D': {"char": "Δ", "name": "Greek capital letter delta"},
'E': {"char": "Ε", "name": "Greek capital letter epsilon"},
'Z': {"char": "Ζ", "name": "Greek capital letter zeta"},
'H': {"char": "Η", "name": "Greek capital letter eta"},
'Q': {"char": "Θ", "name": "Greek capital letter theta"},
'I': {"char": "Ι", "name": "Greek capital letter iota"},
'K': {"char": "Κ", "name": "Greek capital letter kappa"},
'L': {"char": "Λ", "name": "Greek capital letter lamda"},
'M': {"char": "Μ", "name": "Greek capital letter mu"},
'N': {"char": "Ν", "name": "Greek capital letter nu"},
'X': {"char": "Ξ", "name": "Greek capital letter xi"},
'O': {"char": "Ο", "name": "Greek capital letter omicron"},
'P': {"char": "Π", "name": "Greek capital letter pi"},
'R': {"char": "Ρ", "name": "Greek capital letter rho"},
'S': {"char": "Σ", "name": "Greek capital letter sigma"},
'T': {"char": "Τ", "name": "Greek capital letter tau"},
'U': {"char": "Υ", "name": "Greek capital letter upsilon"},
'F': {"char": "Φ", "name": "Greek capital letter phi"},
'C': {"char": "Χ", "name": "Greek capital letter chi"},
'Y': {"char": "Ψ", "name": "Greek capital letter psi"},
'W': {"char": "Ω", "name": "Greek capital letter omega"},
'a': {"char": "α", "name": "Greek small letter alpha"},
'b': {"char": "β", "name": "Greek small letter beta"},
'g': {"char": "γ", "name": "Greek small letter gamma"},
'd': {"char": "δ", "name": "Greek small letter delta"},
'e': {"char": "ε", "name": "Greek small letter epsilon"},
'z': {"char": "ζ", "name": "Greek small letter zeta"},
'h': {"char": "η", "name": "Greek small letter eta"},
'q': {"char": "θ", "name": "Greek small letter theta"},
'i': {"char": "ι", "name": "Greek small letter iota"},
'k': {"char": "κ", "name": "Greek small letter kappa"},
'l': {"char": "λ", "name": "Greek small letter lamda"},
'm': {"char": "μ", "name": "Greek small letter mu"},
'n': {"char": "ν", "name": "Greek small letter nu"},
'x': {"char": "ξ", "name": "Greek small letter xi"},
'o': {"char": "ο", "name": "Greek small letter omicron"},
'p': {"char": "π", "name": "Greek small letter pi"},
'r': {"char": "ρ", "name": "Greek small letter rho"},
'V': {"char": "ς", "name": "Greek small letter final sigma"},
's': {"char": "σ", "name": "Greek small letter sigma"},
't': {"char": "τ", "name": "Greek small letter tau"},
'u': {"char": "υ", "name": "Greek small letter upsilon"},
'f': {"char": "φ", "name": "Greek small letter phi"},
'c': {"char": "χ", "name": "Greek small letter chi"},
'y': {"char": "ψ", "name": "Greek small letter psi"},
'w': {"char": "ω", "name": "Greek small letter omega"},
'J': {"char": "ϑ", "name": "Greek theta symbol"},
'j': {"char": "ϕ", "name": "Greek phi symbol"},
'v': {"char": "ϖ", "name": "Greek pi symbol"},
'¡': {"char": "ϒ", "name": "Greek upsilon with hook symbol"},
'¢': {"char": "′", "name": "Prime"},
'¤': {"char": "⁄", "name": "Fraction slash"},
'²': {"char": "″", "name": "Double prime"},
'¼': {"char": "…", "name": "Horizontal ellipsis"},
'À': {"char": "ℵ", "name": "Alef symbol"},
'Á': {"char": "ℑ", "name": "Black-letter capital I"},
'Â': {"char": "ℜ", "name": "Black-letter capital R"},
'Ã': {"char": "℘", "name": "Script capital P"},
'Ô': {"char": "™", "name": "Trade mark sign (serif)"},
'ä': {"char": "™", "name": "Trade mark sign (sans-serif)"},
'ð': {"char": "€", "name": "Euro sign"},
'«': {"char": "↔", "name": "Left right arrow"},
'¬': {"char": "←", "name": "Leftwards arrow"},
'­': {"char": "↑", "name": "Upwards arrow"},
'®': {"char": "→", "name": "Rightwards arrow"},
'¯': {"char": "↓", "name": "Downwards arrow"},
'¿': {"char": "↵", "name": "Downwards arrow with corner leftwards"},
'Û': {"char": "⇔", "name": "Left right double arrow"},
'Ü': {"char": "⇐", "name": "Leftwards double arrow"},
'Ý': {"char": "⇑", "name": "Upwards double arrow"},
'Þ': {"char": "⇒", "name": "Rightwards double arrow"},
'ß': {"char": "⇓", "name": "Downwards double arrow"},
'"': {"char": "∀", "name": "For all"},
'$': {"char": "∃", "name": "There exists"},
"'": {"char": "∍", "name": "Small contains as member"},
'*': {"char": "∗", "name": "Asterisk operator"},
'-': {"char": "−", "name": "Minus sign"},
'@': {"char": "≅", "name": "Approximately equal to"},
'\\': {"char": "∴", "name": "Therefore"},
'^': {"char": "⊥", "name": "Up tack"},
'~': {"char": "∼", "name": "Tilde operator"},
'£': {"char": "≤", "name": "Less-than or equal to"},
'¥': {"char": "∞", "name": "Infinity"},
'³': {"char": "≥", "name": "Greater-than or equal to"},
'µ': {"char": "∝", "name": "Proportional to"},
'¶': {"char": "∂", "name": "Partial differential"},
'·': {"char": "•", "name": "Bullet"},
'¹': {"char": "≠", "name": "Not equal to"},
'º': {"char": "≡", "name": "Identical to"},
'»': {"char": "≈", "name": "Almost equal to"},
'Ä': {"char": "⊗", "name": "Circled times"},
'Å': {"char": "⊕", "name": "Circled plus"},
'Æ': {"char": "∅", "name": "Empty set"},
'Ç': {"char": "∩", "name": "Intersection"},
'È': {"char": "∪", "name": "Union"},
'É': {"char": "⊃", "name": "Superset of"},
'Ê': {"char": "⊇", "name": "Superset of or equal to"},
'Ë': {"char": "⊄", "name": "Not a subset of"},
'Ì': {"char": "⊂", "name": "Subset of"},
'Í': {"char": "⊆", "name": "Subset of or equal to"},
'Î': {"char": "∈", "name": "Element of"},
'Ï': {"char": "∉", "name": "Not an element of"},
'Ð': {"char": "∠", "name": "Angle"},
'Ñ': {"char": "∇", "name": "Nabla"},
'Õ': {"char": "∏", "name": "N-ary product"},
'Ö': {"char": "√", "name": "Square root"},
'×': {"char": "⋅", "name": "Dot operator"},
'Ù': {"char": "∧", "name": "Logical and"},
'Ú': {"char": "∨", "name": "Logical or"},
'å': {"char": "∑", "name": "N-ary summation"},
'ò': {"char": "∫", "name": "Integral"},
'½': {"char": "⏐", "name": "Vertical line extension"},
'¾': {"char": "⎯", "name": "Horizontal line extension"},
'á': {"char": "〈", "name": "Left-pointing angle bracket"},
'æ': {"char": "⎛", "name": "Left parenthesis upper hook"},
'ç': {"char": "⎜", "name": "Left parenthesis extension"},
'è': {"char": "⎝", "name": "Left parenthesis lower hook"},
'é': {"char": "⎡", "name": "Left square bracket upper corner"},
'ê': {"char": "⎢", "name": "Left square bracket extension"},
'ë': {"char": "⎣", "name": "Left square bracket lower corner"},
'ì': {"char": "⎧", "name": "Left curly bracket upper hook"},
'í': {"char": "⎨", "name": "Left curly bracket middle piece"},
'î': {"char": "⎩", "name": "Left curly bracket lower hook"},
'ï': {"char": "⎪", "name": "Curly bracket extension"},
'ñ': {"char": "〉", "name": "Right-pointing angle bracket"},
'ó': {"char": "⌠", "name": "Top half integral"},
'ô': {"char": "⎮", "name": "Integral extension"},
'õ': {"char": "⌡", "name": "Bottom half integral"},
'ö': {"char": "⎞", "name": "Right parenthesis upper hook"},
'÷': {"char": "⎟", "name": "Right parenthesis extension"},
'ø': {"char": "⎠", "name": "Right parenthesis lower hook"},
'ù': {"char": "⎤", "name": "Right square bracket upper corner"},
'ú': {"char": "⎥", "name": "Right square bracket extension"},
'û': {"char": "⎦", "name": "Right square bracket lower corner"},
'ü': {"char": "⎫", "name": "Right curly bracket upper hook"},
'ý': {"char": "⎬", "name": "Right curly bracket middle piece"},
'þ': {"char": "⎭", "name": "Right curly bracket lower hook"},
'à': {"char": "◊", "name": "Lozenge"},
'§': {"char": "♣", "name": "Black club suit"},
'¨': {"char": "♦", "name": "Black diamond suit"},
'©': {"char": "♥", "name": "Black heart suit"},
'ª': {"char": "♠", "name": "Black spade suit"},
}

def transform(self, data):
raw, xml = data

for node in xml.xpath(".//font-face-symbol"):
try:
item = FONTFACESYMBOL[node.text]
except KeyError:
item = None
else:
item = self.FONTFACESYMBOL.get(node.text)
if item:
node.text = item["char"]
node.tag = "REMOVEFONTFACESYMBOL"

Expand Down
48 changes: 48 additions & 0 deletions tests/test_sps_xml_pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
SetupArticlePipe,
XMLClosePipe,
get_xml_rsps,
XMLFontFaceSymbolPipe,
)


Expand Down Expand Up @@ -146,3 +147,50 @@ def test_XMLClosePipe(self):
"<article/>"
).encode("utf-8")
self.assertEqual(expected, _xml)

class TestXMLFontFaceSymbolPipe(TestCase):
def test_XMLFontFaceSymbolPipe(self):
data = None, etree.fromstring(
'<article>'
'<font-face-symbol face="Symbol">£</font-face-symbol>'
'<font-face-symbol face="Symbol">¨</font-face-symbol>'
'<font-face-symbol face="Symbol">!</font-face-symbol>'
'</article>'
)

_raw, _xml = XMLFontFaceSymbolPipe().transform(data=data)
expected = etree.fromstring(
'<article>'
'≤'
'♦'
'!'
'</article>'
)

self.assertEqual(etree.tostring(expected), etree.tostring(_xml))

def test_XMLFontFaceSymbolPipe_no_replacements(self):
data = None, etree.fromstring(
'<article>'
'<font-face-symbol face="Symbol">!</font-face-symbol>'
'</article>'
)

_raw, _xml = XMLFontFaceSymbolPipe().transform(data=data)

expected = etree.fromstring(
'<article>'
'!'
'</article>'
)

self.assertEqual(etree.tostring(expected), etree.tostring(_xml))

def test_XMLFontFaceSymbolPipe_empty(self):
data = None, etree.fromstring('<article></article>')

_raw, _xml = XMLFontFaceSymbolPipe().transform(data=data)

expected = etree.fromstring('<article></article>')

self.assertEqual(etree.tostring(expected), etree.tostring(_xml))