public function testMarkdownDisabledButForced()
 {
     Config::set('letterpress.markdown.enabled', false);
     $actual = '# This will be processed';
     $expected = '<h1>This will be processed</h1>';
     $this->assertEquals($expected, Markdown::run($actual, true));
 }
Example #2
0
 /**
  * @param array $config
  **/
 protected function setup(array $config = [])
 {
     // apply additional config
     if (count($config) > 0) {
         Config::apply($config);
     }
 }
Example #3
0
    public function testPress()
    {
        $actual = <<<'Markdown'
# Hello World

I am a simpleminded paragraph with no big aims for my life.
Fortunately though, I was blessed with some *emphasis*.

> This is how it always was and always should
> be: Keep making excuses to quote things that don't exist
- Mariella
Markdown;
        $expected = <<<'HTML'
<h1>Hello World</h1>
<p>I am a simple&shy;minded para&shy;graph with no big aims for my life.<br>
Fortunately though, I was blessed with some <em>emphasis</em>.</p>
<figure><blockquote>
<p>This is how it always was and always should
be: Keep making excuses to quote things that don&rsquo;t exist</p>

</blockquote><figcaption>Mari&shy;ella</figcaption></figure>
HTML;
        Config::init();
        $lp = new Letterpress();
        $this->assertEquals($expected, $lp->press($actual));
    }
Example #4
0
 public function __construct()
 {
     // get locale
     $this->locale = Config::get('letterpress.locale');
     // defaults
     if (Config::get('letterpress.microtypography.useDefaults')) {
         $this->fixers = Config::get('jolitypo.defaults');
         // locale additions
         $localeKey = sprintf('jolitypo.%s', $this->locale);
         if (Config::has($localeKey)) {
             $this->fixers = array_merge($this->fixers, Config::get($localeKey));
         }
     }
     // hyphenation
     if (Config::get('letterpress.microtypography.enableHyphenation')) {
         $this->fixers[] = 'Hyphen';
     }
     // user additions
     $this->fixers = array_merge($this->fixers, Config::get('letterpress.microtypography.additionalFixers'));
     if (count($this->fixers) === 0) {
         throw new LetterpressException('Typography fixing requires setting up fixers.');
     }
     $this->fixer = new Fixer($this->fixers);
     $this->fixer->setLocale($this->locale);
 }
 /**
  * @expectedException EFrane\Letterpress\LetterpressException
  * @expectedExceptionMessage Typography fixing requires setting up fixers.
  */
 public function testInstantiateFailsWithoutFixers()
 {
     Config::set('jolitypo.defaults', []);
     Config::set('jolitypo.en_GB', []);
     Config::set('letterpress.microtypography.enableHyphenation', false);
     new TypoFixerFacade();
 }
 public function testLoadsLanguageCodeModifier()
 {
     Config::set('letterpress.markup.addLanguageInfo', true);
     $modifiers = $this->getModifierClassNames(new MarkupProcessor(new Repository()));
     $this->assertContains(BlockQuoteModifier::class, $modifiers);
     $this->assertContains(RemoveEmptyNodesModifier::class, $modifiers);
     $this->assertContains(LanguageCodeModifier::class, $modifiers);
 }
Example #7
0
 public static function run($content, $force = false)
 {
     $output = $content;
     if (Config::get('letterpress.microtypography.enabled') || $force) {
         $fixer = new TypoFixerFacade();
         $output = $fixer->facade_fixer->fix($output);
     }
     return $output;
 }
Example #8
0
 public static function run($content, $force = false)
 {
     $output = $content;
     if (Config::get('letterpress.markup.enabled') || $force) {
         // TODO: implement a way of injecting cached media repositories
         $markup = new MarkupProcessor(new Repository());
         $output = $markup->process($content);
     }
     return $output;
 }
Example #9
0
 public static function run($content, $force = false)
 {
     $output = $content;
     if (Config::get('letterpress.markdown.enabled') || $force) {
         $escaper = new Escaper('/(?P<bbcode>\\[.+?\\].+\\[\\/.+?\\])/', 'bbcode');
         $output = $escaper->escape($output);
         if (!is_a(static::$parsedown, \Parsedown::class)) {
             static::$parsedown = ParsedownFactory::create();
         }
         $output = static::$parsedown->text($output);
         $output = $escaper->replace($output);
     }
     return $output;
 }
 public function candidateModify(DOMNode $parent, DOMNode $candidate)
 {
     $languageCode = strtolower(substr(Config::get('letterpress.locale'), 0, 2));
     if (in_array($candidate->nodeName, $this->textContentElements)) {
         /* @var $candidate \DOMElement*/
         $candidate->setAttribute('lang', $languageCode);
     } else {
         $block = $this->doc->createElement('div');
         $block->setAttribute('lang', $languageCode);
         $candidateClone = $candidate->cloneNode(true);
         $block->appendChild($candidateClone);
         $candidate = $block;
     }
     return $candidate;
 }
Example #11
0
 /**
  * @return \Parsedown
  */
 public static function create()
 {
     $class = '\\Parsedown';
     if (Config::get('letterpress.markdown.useMarkdownExtra')) {
         if (!class_exists('\\ParsedownExtra')) {
             throw new LetterpressException('Enabling MarkdownExtra requires ParsedownExtra to be installed.');
         }
         $class = '\\ParsedownExtra';
     }
     /* @var $instance \Parsedown */
     $instance = new $class();
     $instance->setBreaksEnabled(Config::get('letterpress.markdown.enableLineBreaks'));
     $instance->setMarkupEscaped(!Config::get('letterpress.markdown.escapeMarkup'));
     return $instance;
 }
Example #12
0
 protected function loadMediaModifiers()
 {
     if (!is_a($this->mediaRepository, Repository::class)) {
         throw new LetterpressException('Media repository was not initialized.');
     }
     $iter = new ClassIterator((new Finder())->in(__DIR__ . DIRECTORY_SEPARATOR . 'RichMedia'));
     $iter->enableAutoloading();
     $mediaModifiers = collect();
     foreach ($iter as $mediaModifier) {
         /** @var $mediaModifier \ReflectionClass */
         if ($mediaModifier->isSubclassOf(MediaModifier::class)) {
             $mediaModifiers[$mediaModifier->getShortName()] = $mediaModifier->getName();
         }
     }
     foreach (Config::get('letterpress.media.services') as $serviceName) {
         if ($mediaModifiers->has($serviceName)) {
             $class = $mediaModifiers->get($serviceName);
             $this->modifiers[] = new $class($this->mediaRepository);
         } else {
             throw new LetterpressException('Rich media integration for ' . $serviceName . ' is not available.');
         }
     }
 }
Example #13
0
 public function tearDown()
 {
     parent::tearDown();
     Config::reset(true);
     $this->processor = null;
 }
 /**
  * @dataProvider lineBreaksData
  */
 public function testLineBreaks($enabled, $actual, $expected)
 {
     Config::set('letterpress.markdown.enableLineBreaks', $enabled);
     $instance = ParsedownFactory::create();
     $this->assertEquals($expected, $instance->text($actual));
 }
Example #15
0
 /**
  * @expectedException RuntimeException
  * @expectedExceptionMessage Cloning Letterpress\Config is forbidden.
  */
 public function testClone()
 {
     Config::init();
     $cfg = clone Config::instance();
 }