Skip to content

Commit d144fdf

Browse files
committed
Font name strings
1 parent 61fdc69 commit d144fdf

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

pandas/formats/excel.py

+20-13
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,26 @@ def build_font(self, props):
209209
assert size.endswith('pt')
210210
size = float(size[:-2])
211211

212-
# TODO:
213-
# re.search(r'''(?x)
214-
# (
215-
# "(?:[^"]|\\")+"
216-
# |
217-
# '(?:[^']|\\')+'
218-
# |
219-
# [^'"]+
220-
# )(?=,|\s*$)
221-
# ''')
222-
font_names = [name.strip()
223-
for name in props.get('font-family', '').split(',')
224-
if name.strip()]
212+
font_names_tmp = re.findall(r'''(?x)
213+
(
214+
"(?:[^"]|\\")+"
215+
|
216+
'(?:[^']|\\')+'
217+
|
218+
[^'",]+
219+
)(?=,|\s*$)
220+
''', props.get('font-family', ''))
221+
font_names = []
222+
for name in font_names_tmp:
223+
if name[:1] == '"':
224+
name = name[1:-1].replace('\\"', '"')
225+
elif name[:1] == '\'':
226+
name = name[1:-1].replace('\\\'', '\'')
227+
else:
228+
name = name.strip()
229+
if name:
230+
font_names.append(name)
231+
225232
family = None
226233
for name in font_names:
227234
if name == 'serif':

pandas/tests/formats/test_to_excel.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
# FONT
1313
# - name
1414
('font-family: foo,bar', {'font': {'name': 'foo'}}),
15-
pytest.mark.xfail(('font-family: "foo bar",baz',
16-
{'font': {'name': 'foo bar'}})),
15+
('font-family: "foo bar",baz', {'font': {'name': 'foo bar'}}),
1716
('font-family: foo,\nbar', {'font': {'name': 'foo'}}),
1817
('font-family: foo, bar, baz', {'font': {'name': 'foo'}}),
1918
('font-family: bar, foo', {'font': {'name': 'bar'}}),
19+
('font-family: \'foo bar\', baz', {'font': {'name': 'foo bar'}}),
20+
('font-family: \'foo \\\'bar\', baz', {'font': {'name': 'foo \'bar'}}),
21+
('font-family: "foo \\"bar", baz', {'font': {'name': 'foo "bar'}}),
22+
('font-family: "foo ,bar", baz', {'font': {'name': 'foo ,bar'}}),
2023
# - family
2124
('font-family: serif', {'font': {'name': 'serif', 'family': 1}}),
25+
('font-family: Serif', {'font': {'name': 'serif', 'family': 1}}),
2226
('font-family: roman, serif', {'font': {'name': 'roman', 'family': 1}}),
2327
('font-family: roman, sans-serif', {'font': {'name': 'roman',
2428
'family': 2}}),

0 commit comments

Comments
 (0)