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

Ranged elements #27

Closed
wants to merge 21 commits into from
Closed

Ranged elements #27

wants to merge 21 commits into from

Conversation

mrossinek
Copy link
Member

@mrossinek mrossinek commented Jan 17, 2022

Adds the ranged element syntax discussed on Discord.

  • change spoiler syntax from | to !
  • implement ranged attached modifiers
You can now use the range-modifier `|` to write |*ranged markup like this
which has the benefit

of allowing arbitrary whitespace inside of it      *|.

Ranged markup elements are placed into the paragraph in which they start.
They can contain other in-line syntax like more markup, links, etc.
No detached modifiers, headings, etc. are allowed inside of them.
  • support things like |*/ ranged bold + italic /*|
  • implement general ranged element frames
- |
  If you want to include more elements inside of a single detached modifier you can use a `||` ranged element.
  This allows you to for example include code blocks inside list items:

  @code lua
  print("Hello world!")
  @end
  ---

@mrossinek mrossinek requested a review from vhyrro January 17, 2022 20:26
@mrossinek mrossinek self-assigned this Jan 17, 2022
@gzagatti
Copy link

For future reference, this is how a long list with ranged elements would look like.

I feel that allowing for whitespace between the list items is easier on the eyes. However, it depends on how empty lines straight after the delimiting modifiers are treated. I have assumed that the delimiting modifier only resets after the first non-empty line in which it appears. (Otherwise would it be the case of using ---~?).

Euismod nam consequat fermentum lectus curae mattis et auctor, imperdiet
magna praesent felis platea luctus orci, pulvinar nascetur nisl nulla
fringilla eleifend proin. Venenatis netus velit taciti fusce faucibus,
nunc elementum himenaeos suspendisse, at neque ridiculus lacinia.

- | 
  If you want to include more elements inside of a single detached modifier you can use a `||` ranged element.
  This allows you to for example include code blocks inside list items:

  @code lua
  print("Hello world!")
  @end
  ---

- | 
  Lorem ipsum dolor sit amet consectetur adipiscing elit hac, magnis cras
  curabitur at vulputate potenti. 

  Penatibus etiam fermentum egestas sodales litora quam blandit aptent
  taciti, leo varius primis massa suspendisse augue senectus dictumst,
  ridiculus fringilla cubilia sapien magnis non commodo tempus. 

  - |
    Hello world! The book is on the table

    @code lua
    print(1 + 1)
    @end
    ---
  - |
    @code lua
    print("blue circle")
    @end
    ---
  ---

  --|
    In botany, a fruit is the seed-bearing structure in flowering plants
    that is formed from the ovary after flowering.

    Fruits are the means by which flowering plants (also known as
    angiosperms) disseminate their seeds.
    ---

  -- oranges~

  -- bananas~

- | 
  Convallis mattis nulla habitant neque ridiculus ante libero platea,
  gravida varius sociosqu porttitor dignissim leo volutpat sociis, porta
  facilisis cum sagittis euismod dolor eget. 

  Lorem sit pharetra fermentum eleifend tristique inceptos platea semper
  convallis ullamcorper, et sagittis tellus sodales cubilia dis eu dolor.
  ---

Non curae lobortis ac erat orci dis hac dui, commodo elementum blandit at
arcu placerat sagittis penatibus eleifend, nisl consectetur faucibus
turpis fringilla volutpat mi. Rutrum semper sociis lectus nullam integer
duis posuere, phasellus et cras nibh ornare amet ad vitae, proin nascetur
sodales facilisi eros elit.

I think that the above does not look very bad on the eyes, but the excessive use of --- can be a bit polluting and gets mixed when using sub-items.

Another option would be to use a similar rule that is used for heading. The list only breaks after ---. The next list item is indicated by the delimiter - |. However, this approach would not allow for a list inside of a list as in the example above.

Euismod nam consequat fermentum lectus curae mattis et auctor, imperdiet
magna praesent felis platea luctus orci, pulvinar nascetur nisl nulla
fringilla eleifend proin. Venenatis netus velit taciti fusce faucibus,
nunc elementum himenaeos suspendisse, at neque ridiculus lacinia.

- | 
  If you want to include more elements inside of a single detached modifier you can use a `||` ranged element.
  This allows you to for example include code blocks inside list items:

  @code lua
  print("Hello world!")
  @end

- | 
  Lorem ipsum dolor sit amet consectetur adipiscing elit hac, magnis cras
  curabitur at vulputate potenti. 

  Penatibus etiam fermentum egestas sodales litora quam blandit aptent
  taciti, leo varius primis massa suspendisse augue senectus dictumst,
  ridiculus fringilla cubilia sapien magnis non commodo tempus. 

  @code lua
  print(1 + 1)
  @end

  --|
    In botany, a fruit is the seed-bearing structure in flowering plants
    that is formed from the ovary after flowering.

    Fruits are the means by which flowering plants (also known as
    angiosperms) disseminate their seeds.

  -- oranges~

  -- bananas~

- | 
  Convallis mattis nulla habitant neque ridiculus ante libero platea,
  gravida varius sociosqu porttitor dignissim leo volutpat sociis, porta
  facilisis cum sagittis euismod dolor eget. 

  Lorem sit pharetra fermentum eleifend tristique inceptos platea semper
  convallis ullamcorper, et sagittis tellus sodales cubilia dis eu dolor.

- |
  What we've done is terminated the heading and started out a new 
  paragraph that is no longer "underneath" the heading itself.
---

Non curae lobortis ac erat orci dis hac dui, commodo elementum blandit at
arcu placerat sagittis penatibus eleifend, nisl consectetur faucibus
turpis fringilla volutpat mi. Rutrum semper sociis lectus nullam integer
duis posuere, phasellus et cras nibh ornare amet ad vitae, proin nascetur
sodales facilisi eros elit.

@mrossinek
Copy link
Member Author

Thanks for the input! The final syntax will definitely be closer to your second example because all the intermediate --- will not be required. I.e. a - | will automatically be closed by the next - |. The fact that this means we will not be able to nest lists of the same level within a - | is fine by me since that would not really make sense anyways.
We will formalize this PR a bit more on the weekend 👍

Lists and Quotes are now a subtype of detached modifiers with actually
allow an entire `paragraph` node (instead of just `paragraph_segment`)
to be placed inside of them.
This has the benefit of allowing `_line_break` which means we can avoid
an excessive use of the (soon to be introduced) ranged segments.
A proof of concept idea. Bound to change!
src/scanner.cc Outdated Show resolved Hide resolved
src/scanner.cc Outdated
Comment on lines 742 to 747
/* TODO: what is this?
auto can_have_modifier = [&]()
{
return !m_ActiveModifiers[(VERBATIM_OPEN - BOLD_OPEN) / 2];
};
*/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vhyrro do we really need this?

src/scanner.cc Outdated
{
if (can_have_modifier())
m_ActiveModifiers.set((found_attached_modifier->second - BOLD_OPEN) / 2);
// if (can_have_modifier())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was used here but it was causing issues when implementing ranged modifiers and removing it didn't seem to break anything..

src/scanner.cc Outdated Show resolved Hide resolved
Comment on lines +241 to +247
// TODO(mrossinek): I do not see the need for this. If we do
// need it, we need to extract it into _paragraph again because
// having it here would cause the ends of detached modifiers
// like quotes and lists to break.
// optional(
// $._paragraph_break,
// ),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vhyrro what's your take on this?

@mrossinek
Copy link
Member Author

mrossinek commented Jan 22, 2022

We need to be a bit stricter on how to close the ranged attached modifiers. Currently, the following will be closed prematurely:

|` some long verbatim with `where I show verbatim markup` and finally want to close `|

Instead of the ranged_attached_modifier closing at the end, it will close at `where which is not desired.

EDIT: Fixed in c0c4002

This allows us to write what would normally be non-ranged attached
modifiers inside of ranged-modifiers without affecting their range.
This is very useful because it allows us to write verbatim attached
modifiers within ranged verbatim attached modifiers without messing up
their range.

For example:
    |` In Neorg, verbatim text is written like so:

    `This is verbatim.`
    `|
@mrossinek
Copy link
Member Author

Currently, the following case of nested modifiers is broken:

*bold /italic/_*

The _ is messing things up. I have not yet been able to track down what change caused this problem. I may need to do a bisect but unfortunately these commits are rather large.. Let's see..

mrossinek added a commit that referenced this pull request Apr 3, 2022
Ported implementation from #27.
@mrossinek
Copy link
Member Author

Now that the ranged attached modifiers and the newest indent segment implementation have both been ported to #35 I am closing this PR.

All previously commented issues have been resolved, too 👍

@mrossinek mrossinek closed this Apr 3, 2022
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

Successfully merging this pull request may close these issues.

2 participants