diff --git a/lib/Ufixit.php b/lib/Ufixit.php index fb891af26..1a5200718 100755 --- a/lib/Ufixit.php +++ b/lib/Ufixit.php @@ -250,6 +250,28 @@ public function fixHeading($error_html, $new_content, $submitting_again = false) return $fixed_heading; } + /** + * Makes stylized p elements into headings + * @param string $error_html - The bad html that needs to be fixed + * @param string|array $new_content - The chosen heading level from the user + * @param bool $submitting_again - If the user is resubmitting their error fix + * @return string $fixed_heading - The html with corrected Heading + */ + public function makeHeading($error_html, $new_content, $submitting_again = false) + { + $fixed_heading = ''; + if ($new_content == '') { + return $fixed_heading; + } + + $fixed_heading = $error_html; + + $fixed_heading = preg_replace('/
(?!.*<\/p>)/', '' . $new_content . '>', $fixed_heading);
+
+ return $fixed_heading;
+ }
+
/**
* Fixes table headers by changing td elements to th (and adding proper scope, of course)
* @param string $error_html - The unmodified table without proper headings
diff --git a/public/parseResults.php b/public/parseResults.php
index c252714ac..239b50998 100755
--- a/public/parseResults.php
+++ b/public/parseResults.php
@@ -73,7 +73,7 @@
'report_groups' => $udoit_report->content,
'post_path' => $post_input['path'],
'fixable_error_types' => ["cssTextHasContrast", "imgNonDecorativeHasAlt", "tableDataShouldHaveTh", "tableThShouldHaveScope", "headersHaveText", "aMustContainText", "imgAltIsDifferent", "imgAltIsTooLong"],
- 'fixable_suggestions' => ["aSuspiciousLinkText", "imgHasAlt", "aLinkTextDoesNotBeginWithRedundantWord", "cssTextStyleEmphasize"]
+ 'fixable_suggestions' => ["aSuspiciousLinkText", "imgHasAlt", "aLinkTextDoesNotBeginWithRedundantWord", "cssTextStyleEmphasize", "pNotUsedAsHeader"]
];
diff --git a/public/process.php b/public/process.php
index fba39f45f..c645115c2 100755
--- a/public/process.php
+++ b/public/process.php
@@ -155,7 +155,12 @@
$remove_attr = preg_replace("/ data-api-endpoint.*$/s", "", $data['error_html']);
$data['error_html'] = $remove_attr;
break;
-
+
+ case 'pNotUsedAsHeader':
+ $new_content = filter_input(INPUT_POST, 'newcontent', FILTER_SANITIZE_STRING);
+ $corrected_error = $ufixit->makeHeading($data['error_html'], $new_content);
+ break;
+
case 'tableDataShouldHaveTh':
// fixing table headers is a special case...
$new_content = filter_input(INPUT_POST, 'newcontent', FILTER_SANITIZE_STRING);
diff --git a/templates/partials/result_item/make_heading.php b/templates/partials/result_item/make_heading.php
new file mode 100644
index 000000000..494328d93
--- /dev/null
+++ b/templates/partials/result_item/make_heading.php
@@ -0,0 +1,31 @@
+.
+*
+* Primary Author Contact: Jacob Bates Paragraph text.Paragraph text.
';
+
+ ob_start();
+ $temp = new Ufixit($this->data);
+ $output = $temp->makeHeading($error_html, $new_content);
+
+ $this->assertEquals($expected, $output);
+ $this->checkOutputBuffer();
+ }
+
public function testFixTableHeadersRow() {
$error_html = '
';
$sel_header = 'row';
Header One Header Two 1.30 4.50