Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Corrección al plugin Reparar Markdown x HTML
- =================================
- Edito el archivo markdown/index.php del plugin.
- =======================================================
- 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.
- ===========================
- Hay otra correción en este código que fue hecha por el compañero Franklin y que arreglaba un problema con los strong
- *********************************************
- *********************************************
- <?php
- /*
- Plugin Name: Reparar Markdown x HTML
- Plugin URI: https://javierchirinos.net
- Description: Repara las etiquetas Markdown que no fueron transformadas a HTML al usar Botjael.
- Version: 1.2
- Author: Javier Chirinos
- Author URI: https://javierchirinos.net
- License: GPL
- License URI: https://www.gnu.org/licenses/gpl-3.0.html
- */
- // Esta función busca texto encerrado entre dos asteriscos y lo reemplaza con el mismo texto encerrado entre las etiquetas <strong> y </strong>
- function replace_bold_markdown_with_html($content) {
- $pattern = '/\*\*(.*?)\*\*/';
- $replacement = '<strong>$1</strong>';
- return preg_replace($pattern, $replacement, $content);
- }
- // Esta función busca listas de Markdown y las reemplaza con listas HTML MODIFICADA POR CHATGPT
- //function replace_markdown_list_with_html($content) {
- // $pattern = '/^- (.*?)(?=\n|$)/m';
- // $replacement = '<li>$1</li>';
- // $content = preg_replace($pattern, $replacement, $content);
- // return preg_replace('/(<li>.*?<\/li>)+/s', '<ul>$0</ul>', $content);
- //}
- // Esta función busca listas de Markdown y las reemplaza con listas HTML
- function replace_markdown_list_with_html($content) {
- $pattern = '/^- (.*?)(?=\n|$)/m';
- $replacement = '<li>$1</li>';
- return preg_replace($pattern, $replacement, $content);
- }
- // Esta función busca listas numeradas y aplica negritas a la frase antes de los dos puntos
- function apply_bold_to_numbered_list($content) {
- $pattern = '/^(\d+)\. (.*?): (.*?)(?=\n|$)/m';
- $replacement = '<strong>$1. $2:</strong> $3';
- return preg_replace($pattern, $replacement, $content);
- }
- // 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
- //function apply_bold_and_list_to_dash_list($content) {
- // $pattern = '/^- (.*?): (.*?)(?=\n|$)/m';
- // $replacement = '<li><strong>$1:</strong> $2</li>';
- // $content = preg_replace($pattern, $replacement, $content);
- // return preg_replace('/(<li><strong>.*?<\/strong>.*?<\/li>)+/s', '<ul>$0</ul>', $content);
- //}
- function apply_bold_and_list_to_dash_list($content) {
- $pattern = '/^- (.*?): (.*?)(?=\n|$)/m';
- $replacement = '<li><strong>$1:</strong> $2</li>';
- return preg_replace($pattern, $replacement, $content);
- }
- // Esta función busca frases numeradas y las encierra en etiquetas <strong>
- function bold_numbered_sentences($content) {
- $pattern = '/(\\d+\\.\\s.*:)/';
- preg_match_all($pattern, $content, $matches);
- foreach ($matches[0] as $match) {
- $content = str_replace($match, '<strong>' . $match . '</strong>', $content);
- }
- return $content;
- }
- // 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
- function bold_paragraphs_in_list_items($content) {
- $pattern = '/<li>\s*<p>(.*?):/';
- $replacement = '<li><p><strong>$1:</strong>';
- return preg_replace($pattern, $replacement, $content);
- }
- // 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
- //function bold_list_items($content) {
- // $pattern = '/<li>(.*?):/';
- // $replacement = '<li><strong>$1:</strong>';
- // return preg_replace($pattern, $replacement, $content);
- //}
- function bold_list_items($content) {
- $pattern = '/<li>([^<>]*?):/';
- $replacement = '<li><strong>$1:</strong>';
- return preg_replace($pattern, $replacement, $content);
- }
- // Aplicamos las funciones a los filtros 'the_content' y 'widget_text_content'
- add_filter('the_content', 'replace_bold_markdown_with_html');
- add_filter('the_content', 'replace_markdown_list_with_html');
- add_filter('the_content', 'apply_bold_to_numbered_list');
- add_filter('the_content', 'apply_bold_and_list_to_dash_list');
- add_filter('the_content', 'bold_numbered_sentences');
- add_filter('the_content', 'bold_paragraphs_in_list_items');
- add_filter('the_content', 'bold_list_items');
- add_filter('widget_text_content', 'replace_bold_markdown_with_html');
- add_filter('widget_text_content', 'replace_markdown_list_with_html');
- add_filter('widget_text_content', 'apply_bold_to_numbered_list');
- add_filter('widget_text_content', 'apply_bold_and_list_to_dash_list');
- add_filter('widget_text_content', 'bold_numbered_sentences');
- add_filter('widget_text_content', 'bold_paragraphs_in_list_items');
- add_filter('widget_text_content', 'bold_list_items');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement