Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Links without scheme become relative #18

Closed
franzliedke opened this issue Sep 3, 2015 · 2 comments
Closed

Links without scheme become relative #18

franzliedke opened this issue Sep 3, 2015 · 2 comments

Comments

@franzliedke
Copy link

Not sure whether this is a bug or intended, but both Markdown and BBCode links without a "http://" prefix become links relative to the current directory; and that's often not useful.

See this topic for an example: flarum/flarum@7739217

@JoshyPHP
Copy link
Member

JoshyPHP commented Sep 3, 2015

It's intended. I'll consider adding an option to require a host and/or a scheme.

Did you post the correct link? It doesn't seem related.

@JoshyPHP
Copy link
Member

I'm closing this issue because I don't think I'm going to implement such an option. Currently, the best way to enforce absolute links is to use an attribute filter.

function myfilter($url)
{
    return preg_replace('(^(?!//|\\w+://))', 'http://', $url);
}

$configurator = new s9e\TextFormatter\Configurator;
$configurator->BBCodes->addFromRepository('URL');
$configurator->tags['URL']->attributes['url']->filterChain->prepend('myfilter');

extract($configurator->finalize());

$text = '[url]www.example.org[/url]';
$xml  = $parser->parse($text);
$html = $renderer->render($xml);

die("$html\n");
<a href="http://www.example.org">www.example.org</a>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants