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

Getting the id for headings #7

Open
mriscoc opened this issue Feb 21, 2018 · 6 comments
Open

Getting the id for headings #7

mriscoc opened this issue Feb 21, 2018 · 6 comments

Comments

@mriscoc
Copy link

mriscoc commented Feb 21, 2018

function TLine.stripID(): String;
var
  p, start: integer;
  found: boolean;
  id: String;
begin
  if (isEmpty or (value[1 + Length(value) - trailing - 1] <> '}')) then
    exit('');

  p := leading;
  found := false;
  while (p < Length(value)) and (not found) do
  begin
    case value[1 + p] of
      '\':
        begin
          if (p + 1 < Length(value)) then
          begin
            if (value[1 + p + 1]) = '{' then
            begin
              inc(p);
              break;
            end;
          end;
          inc(p);
          break;
        end;
      '{':
        begin
          found := true;
          break;
        end
    else
      begin
        inc(p);
      end;
    end;
  end;

  if (found) then
  begin
    found := false;
    if (p + 1 < Length(value)) and (value[1 + p + 1] = '#') then
    begin
      start := p + 2;
      p := start;
      while (p < Length(value)) and (not found) do
      begin
        case (value[1 + p]) of
          '\':
            begin
              if (p + 1 < Length(value)) then
              begin
                if (value[1 + p + 1]) = '}' then
                begin
                  inc(p);
                  break;
                end;
              end;
              inc(p);
              break;
            end;
          '}':
            begin
              found := true;
              break;
            end;
        else
          begin
            inc(p);
          end;
        end;
      end;
    end;
   end;

  if (found) then
  begin
    id := Trim( Copy(value, start + 1, p-start));
    if (leading <> 0) then
    begin
      value := Copy(value, 1, leading) + Trim( Copy( value, leading + 1, start -2));
    end
    else
    begin
      value := Trim( Copy(value, leading +1, start -2));
    end;
    trailing := 0;
    if (Length(id) > 0) then
      exit(id)
    else
      exit('');
  end;
  exit('');
end;
@grahamegrieve
Copy link
Owner

so what's the actual issue? Do you have a test case?

@mriscoc
Copy link
Author

mriscoc commented Feb 22, 2018

Test Case for Txtmark extensions: Text anchors

## Headline with ID ##     {#headid}

Another headline with ID   {#headid2}
------------------------

* List with ID             {#listid}

Links: [Foo] (#headid)

This should produce:

<h2 id="headid">Headline with ID</h2>
<h2 id="headid2">Another headline with ID</h2>
<ul>
<li id="listid">List with ID</li>
</ul>
<p>Links: <a href="#headid">Foo</a></p>

The IDs are not inserted into the tags

@BsNoSi
Copy link

BsNoSi commented Feb 29, 2020

Wouldn't it be easier to do something like this:

## Headline with ID
→ becomes →
<h2 id="headline-with-id">Headline with ID</h2>

this is generic and quite easy to deal with because the headline itself is the ID.

@grahamegrieve
Copy link
Owner

well, maybe. What is common mark doing?

@grahamegrieve
Copy link
Owner

https://talk.commonmark.org/t/anchors-in-markdown/247. Per the first example. I'll implement it when I get a chance

@BsNoSi
Copy link

BsNoSi commented Mar 7, 2020

As far as I can see https://talk.commonmark.org/t/anchors-in-markdown/247 gives no final decision on that. Several compilers implicitly generate headline IDs by text (my example). But there is still an option vor anchors missing. I'd prefer something like :[jumpto] which would be close to footnote/image reference design.

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

3 participants