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

<<ItemList>> should show child's content heading as a link. fixes #878 #1632

Merged
merged 1 commit into from
Feb 29, 2024
Merged
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
15 changes: 12 additions & 3 deletions src/moin/help/help-en/MoinWikiMacros.data
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ Those items containing a vowel as the 3rd-to-last character:

===== The "display" parameter =====

All of the following examples display just the "PlainText" item.
All of the following examples display just the "PlainText" item, except for the last example that
displays the subitems of help-en/creole.

'''Markup:'''

Expand All @@ -403,7 +404,7 @@ Displayed using "FullPath" (the default, see examples above):

<<ItemList(item="OtherTextItems", regex="PlainText", display="FullPath")>>

Displayed using "FullPath":
Displayed using "ChildPath":

<<ItemList(item="OtherTextItems", regex="PlainText", display="ChildPath")>>

Expand All @@ -414,6 +415,10 @@ Displayed using "ChildName":
Displayed using "UnCameled":

<<ItemList(item="OtherTextItems", regex="PlainText", display="UnCameled")>>

Displayed using "ItemTitle":

<<ItemList(item="help-en/creole", display="ItemTitle")>>
}}}

'''Result:'''
Expand All @@ -422,7 +427,7 @@ Displayed using "FullPath":

<<ItemList(item="OtherTextItems", regex="PlainText", display="FullPath")>>

Displayed using "FullPath":
Displayed using "ChildPath":

<<ItemList(item="OtherTextItems", regex="PlainText", display="ChildPath")>>

Expand All @@ -434,6 +439,10 @@ Displayed using "UnCameled":

<<ItemList(item="OtherTextItems", regex="PlainText", display="UnCameled")>>

Displayed using "ItemTitle":

<<ItemList(item="help-en/creole", display="ItemTitle")>>


=== MailTo ===

Expand Down
10 changes: 5 additions & 5 deletions src/moin/help/help-en/MoinWikiMacros.meta
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"address": "127.0.0.1",
"comment": "",
"contenttype": "text/x.moin.wiki;charset=utf-8",
"dataid": "9262cede73cd48629f7db4b397ee0835",
"dataid": "b76be52a5dab426ebf4b859e4b8902a6",
"externallinks": [
"https://fontawesome.com/search?o=r&m=free",
"https://moinmo.in/HelpOnMacros/Include"
Expand All @@ -18,16 +18,16 @@
"help-common/logo.png"
],
"itemtype": "default",
"mtime": 1708540585,
"mtime": 1709067921,
"name": [
"MoinWikiMacros"
],
"name_old": [],
"namespace": "help-en",
"rev_number": 1,
"revid": "e1f1896173f24726bdc16811778b1c04",
"sha1": "cb14ea7833e4c378cf6ced5bbaddb00ed05a1d26",
"size": 13140,
"revid": "a9b8fd2812294048bc9ad128bb066323",
"sha1": "78bda38d7b68fd70c5a4b2723fe465f9c987f1a5",
"size": 13401,
"summary": "",
"tags": [
"macros",
Expand Down
3 changes: 3 additions & 0 deletions src/moin/help/help-en/creole%2fsubitem.data
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@

== A Creole Subitem ==

This is the help-en/creole/subitem page
10 changes: 5 additions & 5 deletions src/moin/help/help-en/creole%2fsubitem.meta
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
"address": "127.0.0.1",
"comment": "",
"contenttype": "text/x.moin.wiki;charset=utf-8",
"dataid": "5385292d678f4457987e9fae0576af7e",
"dataid": "fc1d12f9f0784a36ad48e1194a659763",
"externallinks": [],
"itemid": "8594e340fa0e45cab39a38d51d62e77c",
"itemlinks": [],
"itemtransclusions": [],
"itemtype": "default",
"mtime": 1681742379,
"mtime": 1709063783,
"name": [
"creole/subitem"
],
"name_old": [],
"namespace": "help-en",
"rev_number": 1,
"revid": "9b2e7af6bf7a4ec7a87f94a9bce7b724",
"sha1": "d8ae493e88b3724f9d229bff4805bb95afdfe38c",
"size": 39,
"revid": "be4bcb021d9a4b5c9998c6ef592ec9f9",
"sha1": "5fb82ce4b9fd0152d87d5aeb4f31ff058651dd9a",
"size": 68,
"summary": "",
"tags": [],
"wikiname": "MyMoinMoin"
Expand Down
3 changes: 1 addition & 2 deletions src/moin/macros/ItemList.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
blocks of lowercase characters or numbers and an
uppercase character.

ItemTitle : Use the title from the first header in the linked
item [*** NOT IMPLEMENTED YET ***]
ItemTitle : Use the title from the first header in the linked item

Notes:

Expand Down
28 changes: 25 additions & 3 deletions src/moin/macros/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"""

import re

from moin.constants.keys import CURRENT, CONTENTTYPE
from moin.utils import iri
from moin.items import Item
from moin.utils.tree import html
Expand Down Expand Up @@ -62,6 +64,27 @@ def get_item_names(name='', startswith='', kind='files', skiptag=''):
return item_names


def extract_h1(item_name):
"""
Return the first heading found in the item's content
"""
item = Item.create(item_name, rev_id=CURRENT)
contenttype = item.meta[CONTENTTYPE]
if 'x.moin.wiki' not in contenttype and 'x.moin.creole' not in contenttype:
return _('{item_name} content type is not moinwiki or creole').format(item_name=item_name)
item.rev.data.seek(0)
content = item.rev.data.read()
content = content.decode("utf-8")
lines = content.splitlines()
for line in lines:
line = line.rstrip()
if line:
if line.startswith('=') and line.endswith('='):
title = line.replace('=', '').strip()
return title
return _('No heading found in item: {item_name}').format(item_name=item_name)


def fail_message(msg, severity='error'):
"""
Return an error message in admonition-like format.
Expand Down Expand Up @@ -150,7 +173,7 @@ def create_pagelink_list(self, pagenames, ordered=False, display="FullPath"):
blocks of lowercase characters or numbers and an
uppercase character.
skiptag : skip items with this tag
ItemTitle : Use the title from the first header in the linked page *not implemented
ItemTitle : Use the title from the first header in the linked page
"""

page_list = moin_page.list(attrib={moin_page.item_label_generate: ordered and 'ordered' or 'unordered'})
Expand All @@ -177,7 +200,7 @@ def create_pagelink_list(self, pagenames, ordered=False, display="FullPath"):
tempname = re.sub("([a-z0-9])([A-Z])", r"\g<1> \g<2>", fqname[(index + 1):]) # space before a cap char
linkname = re.sub("([a-zA-Z])([0-9])", r"\g<1> \g<2>", tempname)
elif display == "ItemTitle":
raise NotImplementedError(_('"ItemTitle" is not implemented yet.'))
linkname = extract_h1(pagename.fullname)
else:
raise KeyError(_('Unrecognized display value "%s".' % display))

Expand All @@ -200,7 +223,6 @@ def create_multi_pagelink_list(self, itemnames, namespace):

namespace: Namespace of items
"""

result_body = []
initials_linklist = []
initial_letter = ' '
Expand Down