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

Remove all remaining anch() macro calls #14063

Merged
merged 1 commit into from
Mar 19, 2022
Merged

Remove all remaining anch() macro calls #14063

merged 1 commit into from
Mar 19, 2022

Conversation

queengooborg
Copy link
Collaborator

@queengooborg queengooborg commented Mar 19, 2022

This PR is a continuation of #13802. In the first PR, I had developed a script that replaces all calls of the KumaScript anch() macro with Markdown/HTML links. However, the regex for the script did not catch all instances of the macro call, due to a number of factors:

  • Spaces in between the {{ and anch(
  • Capital "A" for "Anch()"
  • Single quotes vs. double quotes for arguments
  • Word wrapping in the middle of the macro (not caught in regex)
  • Additional arguments passed to the macro (not caught in regex)

This PR runs an updated script using the regex expression updated by @cw118 and @yin1999 and tweaks it again to catch single quotes. A few manual replacements are also performed for the edge cases described above.

Script Used:

import {promises as fs} from "fs";
import path from "path";

// https://gist.github.com/lovasoa/8691344
async function* walk(dir) {
	for await (const d of await fs.opendir(dir)) {
		const entry = path.join(dir, d.name);
		if (d.isDirectory()) yield* walk(entry);
		else if (d.isFile() && d.name != ".DS_Store") yield entry;
	}
}
// END SNIPPET

const re = /([\w"]+>[\w\s]*)?(`)?(?<!\\){{[ ]?[aA]nch[ ]?\((["'])(?<link>(?:(?=(\\?))\5.)*?)\3(?:,[ ]?(["'])(?<text>(?:(?=(\\?))\8.)*?)\6)?\)[ ]?}}(?:`)?/g;

const main = async () => {
	for await (const p of walk((`${process.env.HOME}/Developer/Gooborg/mdn-content/files`))) {
		const isHTMLFile = p.endsWith('.html');
		let contents = await fs.readFile(p, 'utf-8');
		let changed = false;

		const matches = [...contents.matchAll(re)];
		for (const match of matches) {
			const isHTML = isHTMLFile || !!match[1];

			let text = match.groups.
			text || match.groups.link;
			if (match[2]) text = isHTML ? `<code>${text}</code>` : `\`${text}\``;
			const link = match.groups.link
				.replace(/\n\//g, '')
				.replace(/[\s\(\)]/g, '_')
				.replace(/_+/g, '_')
				.toLowerCase();
			const anchor = isHTML ? `<a href="#${link}">${text}</a>` : `[${text}](#${link})`;

			changed = true;
			contents = contents.replace(match[0], (match[1] || '') + anchor);
		}

		if (changed) {
			await fs.writeFile(p, contents);
		}
	}
}

await main();

@queengooborg queengooborg requested review from a team as code owners March 19, 2022 17:55
@queengooborg queengooborg requested review from jpmedley, dipikabh and estelle and removed request for a team March 19, 2022 17:55
@github-actions github-actions bot added Content:Accessibility Accessibility docs Content:HTML Hypertext Markup Language docs Content:Learn Learning area docs Content:Other Any docs not covered by another "Content:" label Content:WebAPI Web API docs labels Mar 19, 2022
Copy link
Contributor

@teoli2003 teoli2003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes! Good idea!

@teoli2003 teoli2003 merged commit 035dfa0 into mdn:main Mar 19, 2022
@github-actions
Copy link
Contributor

Preview URLs

Flaws

Note! 13 documents with no flaws that don't need to be listed. 🎉

URL: /en-US/docs/Mozilla/Firefox/Releases/7
Title: Firefox 7 for developers
on GitHub
Flaw count: 36

  • macros:
    • /en-US/docs/Web/API/Element/dir does not exist
    • /en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMemoryMultiReporter does not exist
    • /en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMemoryMultiReporterCallback does not exist
    • /en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsISocketTransport does not exist
    • /en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDNSService does not exist
    • and 17 more flaws omitted
  • broken_links:
    • Can't resolve /en-US/docs/Canvas_tutorial/Applying_styles_and_colors#Shadows
    • Can't resolve /en-US/docs/JavaScript/Reference/Global_Objects/Function/arity
    • Can't resolve /en-US/docs/Mozilla/Firefox/Updating_extensions_for_Firefox_7
    • Can't resolve /en-US/docs/Mozilla/Developer_guide/Interface_Compatibility#binary_interfaces
    • Can't resolve /en-US/docs/Mozilla/Add-ons/Add-on_Manager/AddonManager#addstartupchange()
    • and 9 more flaws omitted

URL: /en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_slider_role
Title: Using the slider role
on GitHub
Flaw count: 5

  • broken_links:
    • Can't resolve /en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-valuemin_attribute
    • Can't resolve /en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-valuemax_attribute
    • Can't resolve /en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-valuenow_attribute
    • Can't resolve /en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-valuetext_attribute
    • Can't resolve /en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-orientation_attribute

URL: /en-US/docs/Web/HTML/Element/input
Title: <input>: The Input (Form Input) element
on GitHub
Flaw count: 4

  • macros:
    • /en-US/docs/Web/API/ValidityState/valueMissing does not exist
    • /en-US/docs/Web/API/ValidityState/valueMissing does not exist
    • /en-US/docs/Web/API/ValidityState/valid does not exist
    • /en-US/docs/Web/API/ValidityState/customError does not exist

URL: /en-US/docs/Web/XSLT/PI_Parameters
Title: PI Parameters
on GitHub
Flaw count: 3

  • broken_links:
    • Can't resolve /en-US/XSLTProcessor
    • Can't resolve /en-US/Firefox_2
    • Can't resolve /en-US/XPath

URL: /en-US/docs/Web/API/File_Handle_API
Title: FileHandle API
on GitHub
Flaw count: 15

  • macros:
    • /en-US/docs/Web/API/IDBDatabase/createMutableFile does not exist
    • /en-US/docs/Web/API/IDBDatabase/mozCreateFileHandle does not exist
    • /en-US/docs/Web/API/FileHandle redirects to /en-US/docs/Web/API/IDBMutableFile
    • /en-US/docs/Web/API/IDBDatabase/createMutableFile does not exist
    • /en-US/docs/Web/API/FileHandle redirects to /en-US/docs/Web/API/IDBMutableFile
    • and 8 more flaws omitted
  • broken_links:
    • Is currently http:// but can become https://
    • Is currently http:// but can become https://

URL: /en-US/docs/Web/API/Element/getAttributeNS
Title: Element.getAttributeNS()
on GitHub
Flaw count: 2

  • macros:
    • wrong xref macro used (consider changing which macro you use)
  • broken_links:
    • Can't resolve /en-US/docs/Mozilla/Add-ons/Code_snippets/getAttributeNS

URL: /en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications
Title: Writing WebSocket client applications
on GitHub
Flaw count: 4

  • macros:
    • /en-US/docs/Web/API/WebSocket/onerror redirects to /en-US/docs/Web/API/WebSocket/error_event
    • /en-US/docs/Web/API/WebSocket/onclose redirects to /en-US/docs/Web/API/WebSocket/close_event
    • /en-US/docs/Web/API/WebSocket/onopen redirects to /en-US/docs/Web/API/WebSocket/open_event
    • /en-US/docs/Web/API/WebSocket/onmessage redirects to /en-US/docs/Web/API/WebSocket/message_event

URL: /en-US/docs/Web/API/Document/createNodeIterator
Title: Document.createNodeIterator()
on GitHub
Flaw count: 1

  • macros:
    • wrong xref macro used (consider changing which macro you use)

URL: /en-US/docs/Web/API/Document/title
Title: Document.title
on GitHub
Flaw count: 1

  • macros:
    • wrong xref macro used (consider changing which macro you use)

URL: /en-US/docs/Web/API/Document/createEvent
Title: Document.createEvent()
on GitHub
Flaw count: 1

  • macros:
    • wrong xref macro used (consider changing which macro you use)

URL: /en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers
Title: Using Service Workers
on GitHub
Flaw count: 2

  • macros:
    • /en-US/docs/Web/API/PeriodicSyncRegistration does not exist
    • /en-US/docs/Web/API/SyncRegistration does not exist

URL: /en-US/docs/Web/API/PushManager/registrations
Title: PushManager.registrations()
on GitHub
Flaw count: 2

  • macros:
    • /en-US/docs/Web/API/DOMRequest does not exist
    • /en-US/docs/Web/API/DOMRequest does not exist

URL: /en-US/docs/Web/API/PushManager/unregister
Title: PushManager.unregister()
on GitHub
Flaw count: 2

  • macros:
    • /en-US/docs/Web/API/DOMRequest does not exist
    • /en-US/docs/Web/API/DOMRequest does not exist

URL: /en-US/docs/MDN/Structures/Macros/Other
Title: Other macros
on GitHub
Flaw count: 4

  • macros:
    • `/home/runner/work/content/content/node_modules/@mdn/yari/kumascript/macros/page.ejs:23
      21| }
      22| %>

23| <%- await wiki.page(url, $1, $2, $3, $4) %>
24|

unable to find an HTML element with an "id" of "how_you_can_help" within /en-us/docs/mdn/about`

  • `/home/runner/work/content/content/node_modules/@mdn/yari/kumascript/macros/page.ejs:23
    21| }
    22| %>

23| <%- await wiki.page(url, $1, $2, $3, $4) %>
24|

unable to find an HTML element with an "id" of "how_you_can_help" within /en-us/docs/mdn/about`

  • broken_links:
    • Can't resolve /en-US/docs/Mozilla/Developer_guide/Source_Code/CVS
    • Can't resolve /en-US/docs/Mozilla/Developer_guide/mozilla-central

External URLs

URL: /en-US/docs/Mozilla/Firefox/Releases/7
Title: Firefox 7 for developers
on GitHub

No new external URLs


URL: /en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_slider_role
Title: Using the slider role
on GitHub

No new external URLs


URL: /en-US/docs/Web/Accessibility/ARIA/Roles/feed_role
Title: ARIA: feed role
on GitHub

No new external URLs


URL: /en-US/docs/Web/HTML/Attributes/rel
Title: HTML attribute: rel
on GitHub

No new external URLs


URL: /en-US/docs/Web/HTML/Element/input
Title: <input>: The Input (Form Input) element
on GitHub

No new external URLs


URL: /en-US/docs/Web/XSLT/PI_Parameters
Title: PI Parameters
on GitHub

No new external URLs


URL: /en-US/docs/Web/Guide/Audio_and_video_delivery/Adding_captions_and_subtitles_to_HTML5_video
Title: Adding captions and subtitles to HTML5 video
on GitHub

No new external URLs


URL: /en-US/docs/Web/Guide/Audio_and_video_delivery/Cross-browser_audio_basics
Title: Cross-browser audio basics
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/RTCIceCandidate/relatedPort
Title: RTCIceCandidate.relatedPort
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
Title: Using server-sent events
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/WebXR_Device_API/Inputs
Title: Inputs and input sources
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/File_Handle_API
Title: FileHandle API
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/Element/getAttributeNS
Title: Element.getAttributeNS()
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB
Title: Using IndexedDB
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications
Title: Writing WebSocket client applications
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/Performance_API/Using_the_Performance_API
Title: Using the Performance API
on GitHub


URL: /en-US/docs/Web/API/HTML_Drag_and_Drop_API
Title: HTML Drag and Drop API
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/Document/createNodeIterator
Title: Document.createNodeIterator()
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/Document/title
Title: Document.title
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/Document/createEvent
Title: Document.createEvent()
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers
Title: Using Service Workers
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/Fullscreen_API/Guide
Title: Guide to the Fullscreen API
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/Performance_Timeline
Title: Performance Timeline
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/PushManager/registrations
Title: PushManager.registrations()
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/PushManager/unregister
Title: PushManager.unregister()
on GitHub

No new external URLs


URL: /en-US/docs/MDN/Structures/Macros/Other
Title: Other macros
on GitHub

No new external URLs


URL: /en-US/docs/MDN/Tools/KumaScript
Title: KumaScript
on GitHub

No new external URLs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:Accessibility Accessibility docs Content:HTML Hypertext Markup Language docs Content:Learn Learning area docs Content:Other Any docs not covered by another "Content:" label Content:WebAPI Web API docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants