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

add extension in link text #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- name: Install dependencies
run: |
pip install -r requirements.txt -c constraints_plone${{ matrix.plone }}.txt
pip install setuptools==41.2.0
cp test_plone${{ matrix.plone }}.cfg buildout.cfg
- name: Install buildout
run: |
Expand Down
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
1.1.5 (unreleased)
------------------

- Nothing changed yet.
- Added extension in link text.
[nzambello]


1.1.4 (2020-10-08)
Expand Down
17 changes: 10 additions & 7 deletions src/collective/outputfilters/enhancelinks/enhance_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,28 @@ def enhance_node_infos(self, node):
link_details = enhancer_provider.get_link_details()
if not link_details:
return
icon_tag = ''
additional_infos = ''
icon_tag = ""
additional_infos = ""
if link_details.get("icon_url"):
icon_tag = etree.Element("img")
icon_tag.set("src", link_details.get("icon_url"))
icon_tag.set("class", "attachmentLinkIcon")
icon_tag.set("alt", link_details.get("extension") or "")
additional_infos = link_details.get("size") + ")"
additional_infos = "{0} {1})".format(
link_details.get("extension"),
link_details.get("size")
)
icon_tag.tail = additional_infos

if node.getchildren():
child = node.getchildren()[-1]
if child.tail:
child.tail = child.tail + ' ('
child.tail = child.tail + " ("
else:
child.append(icon_tag)
child.tail = ' ('
child.tail = " ("
elif additional_infos and text:
node.text = node.text + ' ('
node.text = node.text + " ("
node.append(icon_tag)
if link_details.get("url_suffix"):
self.update_href(node, link_details)
Expand Down Expand Up @@ -164,7 +167,7 @@ def process(self, data):
for tag in root_node.getchildren():
tag_html = etree.tostring(tag, encoding="utf-8", method="html")
if six.PY3:
tag_html = tag_html.decode('utf-8')
tag_html = tag_html.decode("utf-8")
raw_html += tag_html
tail = tag.tail
if tail:
Expand Down
1 change: 1 addition & 0 deletions test_plone52.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ update-versions-file = test_plone52.cfg
plone.testing = 7.0.1
flake8 = 3.3.0
pycodestyle = 2.0.0
importlib-metadata = 1

# Added by buildout at 2020-01-28 11:08:27.735067
PyYAML = 5.3
Expand Down