diff --git a/src/moin/help/help-en/MoinWikiMacros.data b/src/moin/help/help-en/MoinWikiMacros.data index 7a4f89ac6..75c0f7062 100644 --- a/src/moin/help/help-en/MoinWikiMacros.data +++ b/src/moin/help/help-en/MoinWikiMacros.data @@ -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:''' @@ -403,7 +404,7 @@ Displayed using "FullPath" (the default, see examples above): <> -Displayed using "FullPath": +Displayed using "ChildPath": <> @@ -414,6 +415,10 @@ Displayed using "ChildName": Displayed using "UnCameled": <> + +Displayed using "ItemTitle": + +<> }}} '''Result:''' @@ -422,7 +427,7 @@ Displayed using "FullPath": <> -Displayed using "FullPath": +Displayed using "ChildPath": <> @@ -434,6 +439,10 @@ Displayed using "UnCameled": <> +Displayed using "ItemTitle": + +<> + === MailTo === diff --git a/src/moin/help/help-en/MoinWikiMacros.meta b/src/moin/help/help-en/MoinWikiMacros.meta index 1f0e1788d..50fec5d76 100644 --- a/src/moin/help/help-en/MoinWikiMacros.meta +++ b/src/moin/help/help-en/MoinWikiMacros.meta @@ -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" @@ -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", diff --git a/src/moin/help/help-en/creole%2fsubitem.data b/src/moin/help/help-en/creole%2fsubitem.data index 049631683..22b5110cc 100644 --- a/src/moin/help/help-en/creole%2fsubitem.data +++ b/src/moin/help/help-en/creole%2fsubitem.data @@ -1 +1,4 @@ + +== A Creole Subitem == + This is the help-en/creole/subitem page diff --git a/src/moin/help/help-en/creole%2fsubitem.meta b/src/moin/help/help-en/creole%2fsubitem.meta index 13e250fc3..66537c24e 100644 --- a/src/moin/help/help-en/creole%2fsubitem.meta +++ b/src/moin/help/help-en/creole%2fsubitem.meta @@ -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" diff --git a/src/moin/macros/ItemList.py b/src/moin/macros/ItemList.py index c5eff71fa..191074a8c 100644 --- a/src/moin/macros/ItemList.py +++ b/src/moin/macros/ItemList.py @@ -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: diff --git a/src/moin/macros/_base.py b/src/moin/macros/_base.py index b23b60cad..d9e7f43d1 100644 --- a/src/moin/macros/_base.py +++ b/src/moin/macros/_base.py @@ -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 @@ -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. @@ -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'}) @@ -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)) @@ -200,7 +223,6 @@ def create_multi_pagelink_list(self, itemnames, namespace): namespace: Namespace of items """ - result_body = [] initials_linklist = [] initial_letter = ' '