Advertisement
El_Rizos

Corrección al plugin Reparar Markdown x HTML

Feb 14th, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. Corrección al plugin Reparar Markdown x HTML
  2. =================================
  3.  
  4. Edito el archivo markdown/index.php del plugin.
  5. =======================================================
  6. El codigo que dice MODIFICADA POR CHATGPT es el cambiado. Esa parte del código está comentado (con // al principio de cada linea). Y a continuación incluyo el código correcto.
  7. ===========================
  8. Hay otra correción en este código que fue hecha por el compañero Franklin y que arreglaba un problema con los strong
  9. *********************************************
  10. *********************************************
  11.  
  12. <?php
  13. /*
  14. Plugin Name: Reparar Markdown x HTML
  15. Plugin URI: https://javierchirinos.net
  16. Description: Repara las etiquetas Markdown que no fueron transformadas a HTML al usar Botjael.
  17. Version: 1.2
  18. Author: Javier Chirinos
  19. Author URI: https://javierchirinos.net
  20. License: GPL
  21. License URI: https://www.gnu.org/licenses/gpl-3.0.html
  22. */
  23.  
  24. // Esta función busca texto encerrado entre dos asteriscos y lo reemplaza con el mismo texto encerrado entre las etiquetas <strong> y </strong>
  25. function replace_bold_markdown_with_html($content) {
  26. $pattern = '/\*\*(.*?)\*\*/';
  27. $replacement = '<strong>$1</strong>';
  28. return preg_replace($pattern, $replacement, $content);
  29. }
  30.  
  31. // Esta función busca listas de Markdown y las reemplaza con listas HTML MODIFICADA POR CHATGPT
  32. //function replace_markdown_list_with_html($content) {
  33. // $pattern = '/^- (.*?)(?=\n|$)/m';
  34. // $replacement = '<li>$1</li>';
  35. // $content = preg_replace($pattern, $replacement, $content);
  36. // return preg_replace('/(<li>.*?<\/li>)+/s', '<ul>$0</ul>', $content);
  37. //}
  38.  
  39. // Esta función busca listas de Markdown y las reemplaza con listas HTML
  40. function replace_markdown_list_with_html($content) {
  41. $pattern = '/^- (.*?)(?=\n|$)/m';
  42. $replacement = '<li>$1</li>';
  43. return preg_replace($pattern, $replacement, $content);
  44. }
  45.  
  46. // Esta función busca listas numeradas y aplica negritas a la frase antes de los dos puntos
  47. function apply_bold_to_numbered_list($content) {
  48. $pattern = '/^(\d+)\. (.*?): (.*?)(?=\n|$)/m';
  49. $replacement = '<strong>$1. $2:</strong> $3';
  50. return preg_replace($pattern, $replacement, $content);
  51. }
  52.  
  53. // Esta función busca listas que comienzan con un guión, aplica negritas a la frase antes de los dos puntos y encierra en etiquetas <li> MODIFICADA POR CHATGPT
  54. //function apply_bold_and_list_to_dash_list($content) {
  55. // $pattern = '/^- (.*?): (.*?)(?=\n|$)/m';
  56. // $replacement = '<li><strong>$1:</strong> $2</li>';
  57. // $content = preg_replace($pattern, $replacement, $content);
  58. // return preg_replace('/(<li><strong>.*?<\/strong>.*?<\/li>)+/s', '<ul>$0</ul>', $content);
  59. //}
  60.  
  61. function apply_bold_and_list_to_dash_list($content) {
  62. $pattern = '/^- (.*?): (.*?)(?=\n|$)/m';
  63. $replacement = '<li><strong>$1:</strong> $2</li>';
  64. return preg_replace($pattern, $replacement, $content);
  65. }
  66.  
  67. // Esta función busca frases numeradas y las encierra en etiquetas <strong>
  68. function bold_numbered_sentences($content) {
  69. $pattern = '/(\\d+\\.\\s.*:)/';
  70. preg_match_all($pattern, $content, $matches);
  71. foreach ($matches[0] as $match) {
  72. $content = str_replace($match, '<strong>' . $match . '</strong>', $content);
  73. }
  74. return $content;
  75. }
  76.  
  77. // Esta función busca párrafos dentro de elementos de lista que contienen texto seguido de dos puntos y añade la etiqueta <strong> alrededor de ese texto
  78. function bold_paragraphs_in_list_items($content) {
  79. $pattern = '/<li>\s*<p>(.*?):/';
  80. $replacement = '<li><p><strong>$1:</strong>';
  81. return preg_replace($pattern, $replacement, $content);
  82. }
  83.  
  84. // Esta función busca elementos de lista que contienen texto seguido de dos puntos y añade la etiqueta <strong> alrededor de ese texto MODIFICADA POR CHATGPT
  85. //function bold_list_items($content) {
  86. // $pattern = '/<li>(.*?):/';
  87. // $replacement = '<li><strong>$1:</strong>';
  88. // return preg_replace($pattern, $replacement, $content);
  89. //}
  90.  
  91. function bold_list_items($content) {
  92. $pattern = '/<li>([^<>]*?):/';
  93. $replacement = '<li><strong>$1:</strong>';
  94. return preg_replace($pattern, $replacement, $content);
  95. }
  96.  
  97. // Aplicamos las funciones a los filtros 'the_content' y 'widget_text_content'
  98. add_filter('the_content', 'replace_bold_markdown_with_html');
  99. add_filter('the_content', 'replace_markdown_list_with_html');
  100. add_filter('the_content', 'apply_bold_to_numbered_list');
  101. add_filter('the_content', 'apply_bold_and_list_to_dash_list');
  102. add_filter('the_content', 'bold_numbered_sentences');
  103. add_filter('the_content', 'bold_paragraphs_in_list_items');
  104. add_filter('the_content', 'bold_list_items');
  105.  
  106. add_filter('widget_text_content', 'replace_bold_markdown_with_html');
  107. add_filter('widget_text_content', 'replace_markdown_list_with_html');
  108. add_filter('widget_text_content', 'apply_bold_to_numbered_list');
  109. add_filter('widget_text_content', 'apply_bold_and_list_to_dash_list');
  110. add_filter('widget_text_content', 'bold_numbered_sentences');
  111. add_filter('widget_text_content', 'bold_paragraphs_in_list_items');
  112. add_filter('widget_text_content', 'bold_list_items');
  113.  
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement