Skip to content

Commit

Permalink
Add namespaced element option, allow for html components with dashes
Browse files Browse the repository at this point in the history
  • Loading branch information
jefffederman committed Jul 22, 2014
1 parent f79988e commit 8db2a5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 12 additions & 2 deletions sparkup-unittest.py
Expand Up @@ -12,7 +12,8 @@ class SparkupTest:
}
options = {
'default': {'textmate': True, 'no-last-newline': True, 'post-tag-guides': True},
'guides': {'textmate': True, 'no-last-newline': True, 'post-tag-guides': True, 'start-guide-format': 'Begin %s'}
'guides': {'textmate': True, 'no-last-newline': True, 'post-tag-guides': True, 'start-guide-format': 'Begin %s'},
'namespaced-elements': {'textmate': True, 'no-last-newline': True, 'post-tag-guides': True, 'namespaced-elements': True }
}
cases = {
'Simple test': {
Expand Down Expand Up @@ -90,7 +91,7 @@ class SparkupTest:
},
'Expand test': {
'input': 'p#menu > table+ + ul',
'output': '<p id="menu">\n <table cellspacing="0">\n <tr>\n <td>$1</td>\n </tr>\n </table>\n <ul>$2</ul>\n</p>$0'
'output': '<p id="menu">\n <table>\n <tr>\n <td>$1</td>\n </tr>\n </table>\n <ul>$2</ul>\n</p>$0'
},
'Text with dot test': {
'input': 'p { text.com }',
Expand All @@ -112,6 +113,15 @@ class SparkupTest:
'input': 'html>head>title{${title}}',
'output': '<html>\n <head>\n <title>${title}</title>\n </head>\n</html>$0'
},
'HTML component element with dash test': {
'input': 'my-html-component',
'output': '<my-html-component>$1</my-html-component>$0'
},
'XML namespaced element': {
'options': 'namespaced-elements',
'input': 'namespaced-ul',
'output': '<namespaced:ul>$1</namespaced:ul>$0'
},
# Add: text test, broken test, multi-attribute tests, indentation test, start and end comments test
}

Expand Down
6 changes: 4 additions & 2 deletions sparkup.py
Expand Up @@ -853,7 +853,8 @@ def _init_element(self):

# Get the tag name. Default to DIV if none given.
name = re.findall('^([\w\-:]*)', self.str)[0]
name = name.lower().replace('-', ':')
if self.parser.options.options['namespaced-elements'] == True:
name = name.lower().replace('-', ':')

# Find synonyms through this thesaurus
synonyms = self.parser.dialect.synonyms
Expand Down Expand Up @@ -1088,7 +1089,8 @@ def has(self, attr):
except: return False

options = {
'indent-spaces': 4
'indent-spaces': 4,
'namespaced-elements': False,
}
cmdline_keys = [
('h', 'help', 'Shows help'),
Expand Down

0 comments on commit 8db2a5c

Please sign in to comment.