|
@@ -24,8 +24,8 @@ from __future__ import unicode_literals |
|
|
|
|
|
|
|
|
from . import tokens |
|
|
from . import tokens |
|
|
from ..compat import str |
|
|
from ..compat import str |
|
|
from ..nodes import (Argument, Comment, Heading, HTMLEntity, Tag, Template, |
|
|
|
|
|
Text, Wikilink) |
|
|
|
|
|
|
|
|
from ..nodes import (Argument, Comment, ExternalLink, Heading, HTMLEntity, Tag, |
|
|
|
|
|
Template, Text, Wikilink) |
|
|
from ..nodes.extras import Attribute, Parameter |
|
|
from ..nodes.extras import Attribute, Parameter |
|
|
from ..smart_list import SmartList |
|
|
from ..smart_list import SmartList |
|
|
from ..wikicode import Wikicode |
|
|
from ..wikicode import Wikicode |
|
@@ -234,6 +234,22 @@ class Builder(object): |
|
|
else: |
|
|
else: |
|
|
self._write(self._handle_token(token)) |
|
|
self._write(self._handle_token(token)) |
|
|
|
|
|
|
|
|
|
|
|
def _handle_external_link(self, token): |
|
|
|
|
|
"""Handle when an external link is at the head of the tokens.""" |
|
|
|
|
|
brackets, url = token.brackets, None |
|
|
|
|
|
self._push() |
|
|
|
|
|
while self._tokens: |
|
|
|
|
|
token = self._tokens.pop() |
|
|
|
|
|
if isinstance(token, tokens.ExternalLinkSeparator): |
|
|
|
|
|
url = self._pop() |
|
|
|
|
|
self._push() |
|
|
|
|
|
elif isinstance(token, tokens.ExternalLinkClose): |
|
|
|
|
|
if url is not None: |
|
|
|
|
|
return ExternalLink(url, self._pop(), brackets) |
|
|
|
|
|
return ExternalLink(self._pop(), brackets=brackets) |
|
|
|
|
|
else: |
|
|
|
|
|
self._write(self._handle_token(token)) |
|
|
|
|
|
|
|
|
def _handle_token(self, token): |
|
|
def _handle_token(self, token): |
|
|
"""Handle a single token.""" |
|
|
"""Handle a single token.""" |
|
|
if isinstance(token, tokens.Text): |
|
|
if isinstance(token, tokens.Text): |
|
@@ -252,6 +268,8 @@ class Builder(object): |
|
|
return self._handle_comment() |
|
|
return self._handle_comment() |
|
|
elif isinstance(token, tokens.TagOpenOpen): |
|
|
elif isinstance(token, tokens.TagOpenOpen): |
|
|
return self._handle_tag(token) |
|
|
return self._handle_tag(token) |
|
|
|
|
|
elif isinstance(token, tokens.ExternalLinkOpen): |
|
|
|
|
|
return self._handle_external_link(token) |
|
|
|
|
|
|
|
|
def build(self, tokenlist): |
|
|
def build(self, tokenlist): |
|
|
"""Build a Wikicode object from a list tokens and return it.""" |
|
|
"""Build a Wikicode object from a list tokens and return it.""" |
|
|