Skip to content

Commit

Permalink
Italic tags. Empty paragraph tags
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Sep 30, 2024
1 parent cab875e commit 4f8b9fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,26 @@ public function transform(string $data) : string
$data = $this->processWeblinks($data);
$data = $this->processBulletedLists($data);
$data = $this->replaceTags($data, 'bold', 'strong');
$data = $this->replaceTags($data, 'italic', 'em');
$data = $this->replaceEmptyParagraphs($data);
$data = $this->processNumberedLists($data);
return $data;
}

public function replaceEmptyParagraphs(string $data) : string
{
// From time to time we see these kinds of things:
// <p> </p> or <p></p> or <p />.
// We should replace them with nothing.
$variations_to_replace = [
'<p> </p>',
'<p></p>',
'<p />',
'<p/>',
];
return str_replace($variations_to_replace, '', $data);
}

public function processBulletedLists(string $data) : string
{
// The changes should be like this. An input would be
Expand Down
4 changes: 4 additions & 0 deletions tests/assets/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
{
"input": "<list listType=\"numbered\"><listItem>Førerrett for klasse S i minst tre år</listItem><listItem>Godkjenning som trafikklærer eller pedagogisk utdanning som tilsvarer kravene til lærere i det offentlige skoleverk. </listItem></list><p>Søkere som ikke fyller kravet til punkt 2, men er tilknyttet kursarrangør som driver opplæring klasse S kan få innvilget opptak om de fremlegger dokumentasjon fra kursarrangør som viser at de har relevant opplæring og erfaring for å bli instruktør klasse S. Søker må i tillegg dokumentere generell studiekompetanse eller realkompetanse.</p>",
"expected": "<ol><li>Førerrett for klasse S i minst tre år</li><li>Godkjenning som trafikklærer eller pedagogisk utdanning som tilsvarer kravene til lærere i det offentlige skoleverk. </li></ol><p>Søkere som ikke fyller kravet til punkt 2, men er tilknyttet kursarrangør som driver opplæring klasse S kan få innvilget opptak om de fremlegger dokumentasjon fra kursarrangør som viser at de har relevant opplæring og erfaring for å bli instruktør klasse S. Søker må i tillegg dokumentere generell studiekompetanse eller realkompetanse.</p>"
},
{
"input": "<p><italic>The course is designed for those who are at or want to reach a high level in cross-country skiing and biathlon as an athlete or coach. This is a flexible course in sports where the teaching is digital and assembly-based.</italic></p><p><italic>The course gives you theoretical and practical competence to develop yourself to a high international level and, simultaneously, an education that qualifies you to work as a coach at club, regional and national team levels. The study combines theory and practice, which gives a comprehensive understanding of conditions that affect participation, development and learning at all levels, from children's to elite sports. Emphasis is placed on the development of practical pedagogical competence and critical thinking around today's best practice, theory, and the role of trainer.</italic></p><p>The unique thing about the course is that the academics are closely linked to your development as an athlete and are tailored so that you can combine top sports and studies.</p><p> </p>",
"expected": "<p><em>The course is designed for those who are at or want to reach a high level in cross-country skiing and biathlon as an athlete or coach. This is a flexible course in sports where the teaching is digital and assembly-based.</em></p><p><em>The course gives you theoretical and practical competence to develop yourself to a high international level and, simultaneously, an education that qualifies you to work as a coach at club, regional and national team levels. The study combines theory and practice, which gives a comprehensive understanding of conditions that affect participation, development and learning at all levels, from children's to elite sports. Emphasis is placed on the development of practical pedagogical competence and critical thinking around today's best practice, theory, and the role of trainer.</em></p><p>The unique thing about the course is that the academics are closely linked to your development as an athlete and are tailored so that you can combine top sports and studies.</p>"
}
]

0 comments on commit 4f8b9fd

Please sign in to comment.