Giter Club home page Giter Club logo

Comments (19)

erusev avatar erusev commented on August 17, 2024

I believe it is possible.

In fact, it shouldn't be hard to implement.

Would anyone be willing to create a PR?

from parsedown-extra.

graphidev avatar graphidev commented on August 17, 2024

Wait, I just thought that footnotes could serve as permalinks.
So they shouldn't have to be unique (as PHP uniq built-in function) at each Parsedown-extra parsing.

I will think about this and make a PR

from parsedown-extra.

erusev avatar erusev commented on August 17, 2024

So they shouldn't have to be unique (as PHP uniq built-in function) at each Parsedown-extra parsing.

I'm not sure I understand.

My solution would be to keep the footnote data in a class (static) variable. This would make sure that the numbers of footnotes are unique among different instances of the parser.

from parsedown-extra.

graphidev avatar graphidev commented on August 17, 2024

My bad.

I was thinking of a blog architecture where posts are ordered by descending date.

The fn1:1 would target the first foot note of the first post.
However, when a new post is available, then the permalink http://example.com/#fn1:1 will no more refer to the right post (should refer to the second one).

Maybe this could be available as an option to set a custom runtime id. Then the foot notes ids could be something like post456-fn1:23

from parsedown-extra.

graphidev avatar graphidev commented on August 17, 2024

I think the fix made by @robinadr (a234bbe) is a good answer to this probleme. Could it be merged with parsedown-extra in order to get the update from Composer ?

from parsedown-extra.

erusev avatar erusev commented on August 17, 2024

Thanks, I'll have a look as soon as I have some time.

from parsedown-extra.

robinadr avatar robinadr commented on August 17, 2024

I'm debating whether to either add a clearFootnotePrefix() method or make it automatically clear after each text rendering. That being said, it doesn't seem any of the other setters are one time use only.

Anybody have any feedback on this?

from parsedown-extra.

graphidev avatar graphidev commented on August 17, 2024

It would be weird to use twice a same ID (or prefix, as you want) :

  • There is no reason to parse twice the same text
  • Parsing various texts with a same ID could generate conflicts (which is the reason of this issue).

I think, in my personal opinion, that the prefix must be reseted after each text rendering.
However, someone could have an other example that goes to the opposite.

from parsedown-extra.

robinadr avatar robinadr commented on August 17, 2024

I agree. Given that this is a new feature, we have an opportunity now to change the behavior as we imagine it would work best.

Another more generic option is what was previously suggested: keep an internal count and add that on as necessary.

This is simpler but I think it fails when someone might create multiple instances of the parser for a single web page load.

I think having the prefix reset is a good idea, but I'm also wondering if that should be able to be toggled on or off. But then we run the risk of over complication.

On Apr 2, 2015, at 10:37 AM, Sébastien ALEXANDRE [email protected] wrote:

It would be weird to use twice a same ID (or prefix, as you want) :

There is no reason to parse twice the same text
Parsing various texts with a same ID could generate conflicts (which is the reason of this issue).
I think, in my personal opinion, that the prefix must be reseted after each text rendering.
However, someone could have an other example that goes to the opposite.


Reply to this email directly or view it on GitHub.

from parsedown-extra.

graphidev avatar graphidev commented on August 17, 2024

You are right, both generic and custom prefix should be implemented.

Here are the behaviors I suggest :

<?php

    $parsedown = new ParsedownExtra;

    $parsedown->text('...');  # 1
    $parsedown->text('...');  # 2

    $selfReset = true;
    $parsedown->setFootnotePrefix('abcd1234', $selfReset);
    $parsedown->text('...');  # abcd1234

    # if $selfReset is FALSE, then call
    # $parsedown->resetFootnotePrefix(/* FALSE by default */) 
    # in order to reset the custom prefix

    $parsedown->text('...');  # 3 : Previous custom prefix does not reset generic one
    $parsedown->text('...');  # 4

    # Reinstanciated ParsedownExtra does not use previous generic prefix
    $anotherParsedown = new ParsedownExtra;
    $anotherParsedown->text('...'); // # 1

    # reset both generic and custom prefix
    $resetBothCustomAndGeneric = true;
    $parsedown->resetFootnotePrefix($resetBothCustomAndGeneric);
    # private $genericPrefixCount = 0
    # private $customPrefixCount = null

    $parsedown->text('...');  # 1
    $anotherParsedown->text('...');  # 2 : not affected by the first instance reset

    # ...

?>

Keeping generic prefix in memory for all the Parsedown instances may generate some conflicts, such as incrementing count for $anotherParsedown instance when it should not.

from parsedown-extra.

robinadr avatar robinadr commented on August 17, 2024

I feel that's going a little too far. Parsedown is a backend library, so I think it's fair to assume the developer using it can be held responsible to prefix footnotes as necessary. This all depends on the processing of the page (especially multiple parsing passes to be displayed on the same page) as well as how they've worked their code (same parser instance or multiple).

With all these factors dependent on the developer, I think it's most flexible to add a prefixing capability, then let the developer deal with it how they want.

On Apr 3, 2015, at 6:13 AM, Sébastien ALEXANDRE [email protected] wrote:

You are right, both generic and custom prefix should be implemented.

Here are the behaviors I suggest :

text('...'); # 1 $parsedown->text('...'); # 2 $selfReset = true; $parsedown->setFootnotePrefix('abcd1234', $selfReset); $parsedown->text('...'); # abcd1234 # if $selfReset is FALSE, then call # $parsedown->resetFootnotePrefix(/* FALSE by default */) # in order to reset the custom prefix $parsedown->text('...'); # 3 : Previous custom prefix does not reset generic one $parsedown->text('...'); # 4 # Reinstanciated ParsedownExtra does not use previous generic prefix $anotherParsedown = new ParsedownExtra; $anotherParsedown->text('...'); // # 1 # reset both generic and custom prefix $resetBothCustomAndGeneric = true; $parsedown->resetFootnotePrefix($resetBothCustomAndGeneric); # private $genericPrefixCount = 0 # private $customPrefixCount = null $parsedown->text('...'); # 1 $anotherParsedown->text('...'); # 2 : not affected by the first instance reset # ... ``` ?>

Keeping generic prefix in memory for all the Parsedown instances may generate some conflicts, such as incrementing count for $anotherParsedown instance when it should not.


Reply to this email directly or view it on GitHub.

from parsedown-extra.

graphidev avatar graphidev commented on August 17, 2024

My bad, I didn't read correctly your previous comment.

So let's take care of this part only :

$selfReset = true;
$parsedown->setFootnotePrefix('abcd1234', $selfReset);
$parsedown->text('...');  # abcd1234

# if $selfReset is FALSE, then call
# $parsedown->resetFootnotePrefix(/* FALSE by default */) 
# in order to reset the custom prefix

from parsedown-extra.

robinadr avatar robinadr commented on August 17, 2024

I’m still inclined to let the developer take care of it. We can add a resetFootnotePrefix() method if necessary (it would just be setFootnotePrefix(‘’)) but my general philosophy is to leave control up to the developer using the library. It might mean an extra line or two for them, but at the end of the day I value the flexibility. That’s just me, though.

from parsedown-extra.

robinadr avatar robinadr commented on August 17, 2024

I pushed a change that adds clearFootnotePrefix() for now.

from parsedown-extra.

graphidev avatar graphidev commented on August 17, 2024

I just agree with your philosophy. I apologize if my samples wasn't looking that way.

Thanks a lot for you work !

from parsedown-extra.

robinadr avatar robinadr commented on August 17, 2024

No worries, just trying to figure out what the best approach is before it's potentially pushed into the main repo. Waiting to hear what @erusev wants to do.

from parsedown-extra.

erusev avatar erusev commented on August 17, 2024

@robinadr I've been super busy lately. I'll respond as soon as have some time.

from parsedown-extra.

wladston avatar wladston commented on August 17, 2024

Can we merge this in already? :)

from parsedown-extra.

erusev avatar erusev commented on August 17, 2024

could someone experiment w/ the original Markdown Extra and see if this issue is addressed there

from parsedown-extra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.