-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'staging' into deployment
- Loading branch information
Showing
7 changed files
with
59 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Utils; | ||
|
||
class LatexSanitizer | ||
{ | ||
/** | ||
* Converts a single character to a \symbol{...} command | ||
* @param string $char | ||
* @return string $string | ||
*/ | ||
private static function convertCharToSymbol(string $char): string | ||
{ | ||
if($char == ' ') { | ||
return ' '; | ||
} | ||
return "\\symbol{" . mb_ord($char) . "}"; | ||
} | ||
|
||
/** | ||
* Converts string to a relatively safe Latex code by putting every character into a seperate \symbol{...} | ||
* @param string $data | ||
* @return string|null $string | ||
*/ | ||
public static function sanitizeLatex(string|null $data): string | ||
{ | ||
if($data == null) { | ||
return ""; | ||
} | ||
$len = mb_strlen($data); | ||
$result = []; | ||
for ($i = 0; $i < $len; $i++) { | ||
$result[] = LatexSanitizer::convertCharToSymbol(mb_substr($data, $i, 1)); | ||
} | ||
return implode($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters