<?php
/**
 * Replace non breaking space (generated by Pandoc conversion)
 * to spaces since, otherwise, rendering will fail and no output
 * will be done for the sentence/paragraph with that character.
 * A non breaking space is U+00A0 (Unicode) but encoded as C2A0
 * in UTF-8. Replace by a space character
 */
namespace MarkNotes\Plugins\Markdown\Beautify_Actions;

defined('_MARKNOTES') or die('No direct access allowed');

class NBSP
{
	public function doIt(array $params) // : string
	{
		$markdown = $params['markdown'];

		try {
			$markdown = str_replace("\xc2\xa0", " ", $markdown);
		} catch (Exception $e) {
			/*<!-- build:debug -->*/
			$aeDebug = \MarkNotes\Debug::getInstance();
			$aeDebug->log($e->getMessage(), "error", 3);
			/*<!-- endbuild -->*/
		}

		/*<!-- build:debug -->*/
		$aeSettings = \MarkNotes\Settings::getInstance();
		if ($aeSettings->getDebugMode()) {
			if ($params['markdown']!==$markdown) {
				$aeDebug = \MarkNotes\Debug::getInstance();
				$aeDebug->log("   ".__CLASS__." has modify the markdown content", "debug");
			}
		}
		/*<!-- endbuild -->*/

		return $markdown;
	}
}
