mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Handle east asian character column width in the importer
Fixes #682 Closes #923
This commit is contained in:
parent
9ebe06156c
commit
f83d0d3b0c
2 changed files with 19 additions and 2 deletions
|
|
@ -4,7 +4,7 @@ from __future__ import unicode_literals, print_function
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from pelican.tools.pelican_import import wp2fields, fields2pelican, decode_wp_content
|
from pelican.tools.pelican_import import wp2fields, fields2pelican, decode_wp_content, build_header
|
||||||
from pelican.tests.support import (unittest, temporary_folder, mute,
|
from pelican.tests.support import (unittest, temporary_folder, mute,
|
||||||
skipIfNoExecutable)
|
skipIfNoExecutable)
|
||||||
|
|
||||||
|
|
@ -122,3 +122,18 @@ class TestWordpressXmlImporter(unittest.TestCase):
|
||||||
sample_line = re.search(r'- This is a code sample', md).group(0)
|
sample_line = re.search(r'- This is a code sample', md).group(0)
|
||||||
code_line = re.search(r'\s+a = \[1, 2, 3\]', md).group(0)
|
code_line = re.search(r'\s+a = \[1, 2, 3\]', md).group(0)
|
||||||
self.assertTrue(sample_line.rindex('This') < code_line.rindex('a'))
|
self.assertTrue(sample_line.rindex('This') < code_line.rindex('a'))
|
||||||
|
|
||||||
|
|
||||||
|
class TestBuildHeader(unittest.TestCase):
|
||||||
|
def test_build_header(self):
|
||||||
|
header = build_header('test', None, None, None, None, None)
|
||||||
|
self.assertEqual(header, 'test\n####\n\n')
|
||||||
|
|
||||||
|
def test_build_header_with_east_asian_characters(self):
|
||||||
|
header = build_header('これは広い幅の文字だけで構成されたタイトルです',
|
||||||
|
None, None, None, None, None)
|
||||||
|
|
||||||
|
self.assertEqual(header,
|
||||||
|
'これは広い幅の文字だけで構成されたタイトルです\n' +
|
||||||
|
'##############################################\n\n')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -425,8 +425,10 @@ def feed2fields(file):
|
||||||
|
|
||||||
|
|
||||||
def build_header(title, date, author, categories, tags, slug):
|
def build_header(title, date, author, categories, tags, slug):
|
||||||
|
from docutils.utils import column_width
|
||||||
|
|
||||||
"""Build a header from a list of fields"""
|
"""Build a header from a list of fields"""
|
||||||
header = '%s\n%s\n' % (title, '#' * len(title))
|
header = '%s\n%s\n' % (title, '#' * column_width(title))
|
||||||
if date:
|
if date:
|
||||||
header += ':date: %s\n' % date
|
header += ':date: %s\n' % date
|
||||||
if author:
|
if author:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue