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

Improve Updater to not remove useful README titles #770

Merged
merged 5 commits into from Mar 6, 2017

Conversation

javiereguiluz
Copy link
Contributor

This tries to fix #764 by only removing the first <h1> element if it's the first actual element of the README file.

@stof
Copy link
Contributor

stof commented Feb 24, 2017

We should keep removing h2 if it is the first element too. Some projects use a h2 rather than a h1 to take less space in the github rendering

if ($dom->getElementsByTagName('h1')->length) {
// remove first page element if it's a <h1> or <h2>, because it's usually
// the project name or the `README` string which we don't need
if ('h1' === $dom->childNodes->item(0)->nodeName) {
$first = $dom->getElementsByTagName('h1')->item(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

could be simplified:

$first = $dom->childNodes->item(0);

if ($first && ('h1' === $first->nodeName || 'h2' === $first->nodeName)) {
    $first->parentNode->removeChild($first);
}

My snippet also account for the case of empty readme, where there could be no first node.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Much better! Thank you.

@Seldaek
Copy link
Member

Seldaek commented Mar 6, 2017

Thanks!

@Seldaek Seldaek merged commit 6878ab8 into composer:master Mar 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No stripping of first h1/h2 of README when it is not the first content of the README
3 participants