Reformat Date, Remove line break, prepend and append but only after a date is matched?

Thanks for being so clear with your requirements and before/after sample text; that makes it a lot easier to help. In my testing, this macro seems to do what you want (credit to @mrpasini for the action that handles the ordinal date formatting):

Format Books Highlights for Roam Research.kmmacros (12.5 KB)

Feel free to disable the clipboard verification steps at the beginning and end if you find them unnecessary.

2 Likes

Lovely stuff @gglick

1 Like

Wow! Thank you for putting all that effort in! It's very close.

Its odd, the clipboard alert is showing the clipboard but there is another alert that the macro was cancelled due to no highlights being on the clipboard.

However, it is still partially reformatting. I imagine it would be more helpful if I pasted actual notes directly from Books.app:

July 23, 2020

“Usually adult males who are unable to make emotional connections with the women they choose to be intimate with are frozen in time, unable to allow themselves to love for fear that the loved one will abandon them. If the first woman they passionately loved, the mother, was not true to her bond of love, then how can they trust that their partner will be true to love”

I must feel some sense of abandonment on an unconscious level because of being raised by my grandparents, rather than my mom. Though I also think part of my lack of emotion stems from feeling I had to be a protector of my mom from a very early age. Calling the police on Garth when I was maybe 10-12.

July 23, 2020

“I have defined it in a way that blends M. Scott Peck’s notion of love as the will to nurture one’s own and another’s spiritual and emotional growth, with Eric Fromm’s insight that love is action and not solely feeling.”

July 23, 2020

“Women demanded of men that they give more emotionally, but most men really could not understand what was being asked of them. Having cut away the parts of themselves that could feel a wide rage of emotional response, they were too disconnected. They simply could not give more emotionally or even grasp the problem without first reconnecting, reuniting the severed parts.”

Notes From: hooks, bell. “The Will to Change: Men, Masculinity, and Love.” Apple Books.

When I run the macro on those notes it outputs (I uploaded a screenshot since it strips the formatting when I paste it here):

You're welcome, and yes, pasting actual quotes here definitely helps. Unfortunately, I'm not sure what the problem could be for you, because when I run the macro on that text, I get exactly what I believe you described (also, there's a way to keep the formatting when pasting it here; just make sure you use the preformatted text option (the button that looks like </> rather than the blockquote):

[[July 23rd, 2020]]
 “Usually adult males who are unable to make emotional connections with the women they choose to be intimate with are frozen in time, unable to allow themselves to love for fear that the loved one will abandon them. If the first woman they passionately loved, the mother, was not true to her bond of love, then how can they trust that their partner will be true to love”

 I must feel some sense of abandonment on an unconscious level because of being raised by my grandparents, rather than my mom. Though I also think part of my lack of emotion stems from feeling I had to be a protector of my mom from a very early age. Calling the police on Garth when I was maybe 10-12.

[[July 23rd, 2020]]
 “I have defined it in a way that blends M. Scott Peck’s notion of love as the will to nurture one’s own and another’s spiritual and emotional growth, with Eric Fromm’s insight that love is action and not solely feeling.”

[[July 23rd, 2020]]
 “Women demanded of men that they give more emotionally, but most men really could not understand what was being asked of them. Having cut away the parts of themselves that could feel a wide rage of emotional response, they were too disconnected. They simply could not give more emotionally or even grasp the problem without first reconnecting, reuniting the severed parts.”

 Notes From: hooks, bell. “The Will to Change: Men, Masculinity, and Love.” Apple Books.

If you don't need the error checking to make sure the clipboard contains highlights before the macro proceeds, you can just disable the first group of actions that handles that:

Ok so I tested it again by copying the notes I pasted here and it does indeed work. So there must be something weird about the data on the clipboard as it comes directly from Books.app. I'll poke around and see if I can figure out what that might be.

The best thing to do is paste directly from the clipboard from Books.app into the forum using the forum Code Block. This should preserve all characters, except maybe CR.
CRs might be converted to LF when you paste into the forum.

I would suggest using BBEdit, but it also converts CRs to LFs.
Is it possible to export the text from Books.app to a text file? If so, do that and then zip the text file and upload to the forum.

Thank you! It looks like the only options for sharing are to email the notes one at time or select them all and copy. So I guess I'll start there and see if it helps.

July 18, 2020 

“Patriarchal mores teach a form of emotional stoicism to men that says they are more manly if they do not feel, but if by chance they should feel and the feelings hurt, the manly response is to stuff them down, to forget about them, to hope they go away”


July 18, 2020 

“The masculine pretense is that real men feel no pain.”




July 18, 2020 

“The reality is that men are hurting and that the whole culture responds to them by saying, “Please do not tell us what you feel”


July 18, 2020 

“If we cannot heal what we cannot feel, by supporting patriarchal culture that socializes men to deny feelings, we doom them to live in states of emotional numbness. We construct a culture where male pain can have no voice, where male hurt cannot be named or healed.”


July 18, 2020 

“When I was in my twenties, I would go to couples therapy, and my partner of more than ten years would explain how I asked him to talk about his feelings and when he did, I would freak out. He was right. It was hard for me to face that I did not want to hear about his feelings when they were painful or negative, that I did not want my image of the strong man truly challenged by learning of his weaknesses and vulnerabilities”


July 18, 2020 

“Many women cannot hear male pain about love because it sounds like an indictment of female failure. Since sexist norms have taught us that loving is our task whether in our role as mothers or lovers or friends, if men say they are not loved, then we are at fault; we are to blame”


July 18, 2020 

“Anger is the best hiding place for anybody seeking to conceal pain or anguish of spirit”


July 18, 2020 

“Indeed, men who feel, who love, often hide their emotional awareness from other men for fear of being attacked and shamed.”


July 18, 2020 

“When he was home, his favorite way of relating was to tease and taunt his son mercilessly, in a biting voice full of sarcasm and contempt, a voice that could humiliate with just a word”


July 18, 2020 

“Yet life has shown me that any time a single male dares to transgress patriarchal boundaries in order to love, the lives of women, men, and children are fundamentally changed for the better”


July 18, 2020 

“To create loving men, we must love males. Loving maleness is different from praising and rewarding males for living up to sexist-defined notions of male identity. Caring about men because of what they do for us is not the same as loving males for simply being.”


July 18, 2020 

“In an antipatriarchal culture males do not have to prove their value and worth. They know from birth that simply being gives them value, the right to be cherished and loved.”


July 18, 2020 

“The damage done to his self-esteem in boyhood has lingered throughout his life, for he continues to grapple with the issue of whether he will define himself or allow himself to be defined by patriarchal standards”


July 19, 2020 

“He knew there was something wrong within, even though he had not yet found a language to articulate what was missing.”


July 19, 2020 

“the moment that they were compelled to give up their right to feel, to love, in order to take their place as patriarchal men.”

I'm sure I had this moment but I don't remember what or when it was


July 19, 2020 

“Of course they never answer the question of what will motivate males in a patriarchal culture who have been taught that to love emasculates them to change, to choose love, when the choice means that they must stand against patriarchy, against the tyranny of the familiar”


Notes From: hooks, bell. “The Will to Change: Men, Masculinity, and Love.” Apple Books. 

OK, thanks.
You had a minor error in the use of the triple backquotes -- they must appear on a line by themselves. I fixed your post and then copied your text.
It works fine in my macro.

Okay, I think (hope) I figured it out. In the new text, there was a space hidden after the year that was causing the simple regular expression I was using to find the date to fail. I replaced it with a more robust regex that, assuming the format here is indeed the format copied from Books, should be better at finding the dates. Give this version a try and see if it helps:

Format Books Highlights for Roam Research 1.1.kmmacros (13.0 KB)

1 Like

Fantastic! Works perfectly now. Thank you so much. It would have taken me ages to make any progress on this. Plus now I can study your creation and learn from it. Great community here!

2 Likes

Sorry to dig up an older thread. This was working perfectly but now I'm getting some inconsistent results. I looked through the macro actions but I don't think I understand it well enough to identify potential problem areas. Here are the 3 ways I'm seeing the data being pasted into Roam:

I suspect this first example is to due with the highlight dates being out of order? The first date and highlight are inline instead of the highlight being indented one level. The next date and highlight is correct but then each indentation under that is incorrect.

The next one worked as expected. Date is formatted correctly, highlight is indented one level under the date:

Then the 3rd attempt failed in a different way. Dates and highlight are at the same level of indent:

For context. In Roam, tab indents one level each time, shift-tab outdents a level.

You've already helped so much on this, I'll understand if this going beyond what is reasonable. But I figured I'd throw it out there. Thanks!

Hmm. I have an idea as to what might be going wrong, but I can't test it easily without sample text in its original form (i.e. exactly how it's formatted when copied from Books). Try this updated macro for now, and if it doesn't work, I'll need you to post the original Books quotes that get mis-formatted, before running them through the macro.

Format Books Highlights for Roam Research 1.2.kmmacros (13.8 KB)

Thank you. That one does seem to yield consistent results but still formatting a little strangely. Here is the clipboard from the first example in my previous post.


“However, most men have not consciously chosen patriarchy as the ideology they want to govern their lives, their beliefs, and actions. Patriarchal culture is the system they were born within and socialized to accept, yet in all areas of their lives most men have rebelled in small ways against the patriarchy, have resisted absolute allegiance to patriarchal thinking and practice”


August 3, 2020 

“And even though the man-hating women were a small minority of women’s libbers, they received the most attention. Failing to care for women rightly, men through continual acts of domination had actually created the cultural context for feminist rebellion”


August 4, 2020 

“It was easier to see that even if individual men divested themselves of patriarchal privilege, the system of patriarchy, sexism, and male domination would still remain intact, and women would still be exploited and oppressed.”


August 4, 2020 

“Feminist thinking teaches us all, males especially, how to love justice and freedom in ways that foster and affirm life.”


August 4, 2020 

“Clearly, men need new models for self-assertion that do not require the construction of an enemy “other,” be it a woman or the symbolic feminine, for them to define themselves against. Starting in early childhood, males need models of men with integrity, that is, men who are whole, who are not divided against themselves. While individual women acting as single mothers have shown that they can raise healthy, loving boys who become responsible, loving men, in every case where this model of parenting has been successful, women have chosen adult males—fathers, grandfathers, uncles, friends, and comrades—to exemplify for their sons the adult manhood they should strive to achieve.”


August 4, 2020 

“Rejecting this model for a feminist masculinity means that we must define maleness as a state of being rather than as performance. Male being, maleness, masculinity must stand for the essential core goodness of the self, of the human body that has a penis. Many of the critics who have written about masculinity suggest that we need to do away with the term, that we need “an end to manhood.” Yet such a stance furthers the notion that there is something inherently evil, bad, or unworthy about maleness.”


August 4, 2020 

“And those of us committed to ending patriarchy can touch the hearts of real men where they live, not by demanding that they give up manhood or maleness, but by asking that they allow its meaning to be transformed, that they become disloyal to patriarchal masculinity in order to find a place for the masculine that does not make it synonymous with domination or the will to do violence.”


August 4, 2020 

“Patriarchal masculinity teaches males to be pathologically narcissistic, infantile, and psychologically dependent for self-definition on the privileges (however relative) that they receive from having been born male. Hence many males feel that their very existence is threatened if these privileges are taken away”


August 4, 2020 

“Rather than defining strength as “power over,” feminist masculinity defines strength as one’s capacity to be responsible for self and others”


August 4, 2020 

“What the world needs now is liberated men who have the qualities Silverstein cites, men who are “empathic and strong, autonomous and connected, responsible to self, to family and friends, and to society, and capable of understanding how those responsibilities are, ultimately, inseparable.”


August 4, 2020 

“Choosing loyalty to manhood over selfhood leads inevitably to injustice…loving justice more than manhood relocates personal identity in selfhood—relationally, reciprocally, realistically.”


Notes From: hooks, bell. “The Will to Change: Men, Masculinity, and Love.” Apple Books. 

I just realized something that will probably be helpful. In Roam if you want a line break without creating a new bullet, you hit shift-return instead of just return. In the newest macro it looks to be processing the breaks as shift-return instead of an indented bullet. For example:

Formatted using the most recent version of the macro:

And using return to create new bullets:

The screenshots are helpful, but what we really need to solve your problem, or any problem, is the actual real-world text.

Please post what you showed in screenshots as text using the Code Block.

Did I use the code block incorrectly above my last comment? That's the real world text

All right, here's one that should hopefully keep things more consistent by using tabs instead of spaces. If this still doesn't work, then I'll need you to post the source quotes before running the macro and the inconsistently formatted quotes after running the macro, both in code blocks.

Format Books Highlights for Roam Research 1.2.1.kmmacros (14.2 KB)

Sorry it took me so long to get back to this. So here's the weird thing. It seems to be formatting the text blocks correctly now with the exception of the date. It is putting all the highlights under today's date. Rather than the date the highlight was made in Books.app, when I paste it into Roam. But when I try to paste it here in a code block to show you, it pastes correctly. So Roam must be interpreting it strangely.

You've already worked too hard on this. And now that it seems to be a Roam issue, I can't expect you to investigate further.

Clipboard directly from Books.app:

August 20, 2020 

“I knew my father as the strong man who did not talk, who did not show feelings, who did not give time or attention. He was the pr”


August 10, 2020 

“Any woman who supports patriarchy who then claims to either love the men in her life or be frustrated that they do not love her is in a state of denial.”


August 10, 2020 

“Men will never receive support from patriarchal culture for their emotional development. But if as enlightened witnesses we offer the men we love (our fathers, brothers, lovers, friends, comrades) affirmation that they can change as well as assurance that we will accept them when they are changed, transformation will not seem as risky.”


August 10, 2020 

“But in no way can sex completely fulfill these needs. Such needs can only be fulfilled by healing from the effects of male conditioning and suffusing every area of our lives with relatedness and aliveness.”


August 10, 2020 

“No man who reclaims passion for his life fears the passion in another man. He is not homophobic, for to be so would be a rejection of the self-acceptance and acceptance of others that is essential to the formation and maintenance of self-esteem. If all men were in touch with primal positive passion, the categories of gay and straight would lose their charged significance.”


August 10, 2020 

“Time and time again when I struggled to do the work of love with a male partner who was not changing, I was told to give up on him, to kick him to the curb. I was told I was wasting my time. All this negative feedback made me ponder whether healing places exist where wounded males can go where they will not be turned away, especially when positive change is not happening fast or fast enough. Women who have been victimized by men, women who have suffered ongoing hurt at the hands of men, naturally are wisely cautious about the energy that they can expend in the service of helping men heal. Yet there are many women who have been both helped and hurt by men. Kay Leigh Hagan testifies that the good men in her life have ruined her for man hating:”


August 10, 2020 

“For both men and women, Good Men can be somewhat disturbing to be around because they usually do not act in ways associated with typical men; they listen more than they talk; they self-reflect on their behavior and motives, they actively educate themselves about women’s reality by seeking out women’s culture and listening to women…. They avoid using women for vicarious emotional expression…. When they err—and they do err—they look to women for guidance, and receive criticism with gratitude. They practice enduring uncertainty while waiting for a new way of being to reveal previously unconsidered alternatives to controlling and abusive behavior. They intervene in other men’s misogynist behavior, even when women are not present, and they work hard to recognize and challenge their own. Perhaps most amazingly, Good Men perceive the value of a feminist practice for themselves, and they advocate it not because it’s politically correct, or because they want women to like them, or even because they want women to have equality, but because they understand that male privilege prevents them not only from becoming whole, authentic human beings but also from knowing the truth about the world…. They offer proof that men can change.”


Notes From: hooks, bell. “The Will to Change: Men, Masculinity, and Love.” Apple Books. 

Clipboard after being processed by 1.2.1 of your macro:

[[August 20th, 2020]]
	“I knew my father as the strong man who did not talk, who did not show feelings, who did not give time or attention. He was the pr”
	
	
[[August 10th, 2020]]
	“Any woman who supports patriarchy who then claims to either love the men in her life or be frustrated that they do not love her is in a state of denial.”
	
	
[[August 10th, 2020]]
	“Men will never receive support from patriarchal culture for their emotional development. But if as enlightened witnesses we offer the men we love (our fathers, brothers, lovers, friends, comrades) affirmation that they can change as well as assurance that we will accept them when they are changed, transformation will not seem as risky.”
	
	
[[August 10th, 2020]]
	“But in no way can sex completely fulfill these needs. Such needs can only be fulfilled by healing from the effects of male conditioning and suffusing every area of our lives with relatedness and aliveness.”
	
	
[[August 10th, 2020]]
	“No man who reclaims passion for his life fears the passion in another man. He is not homophobic, for to be so would be a rejection of the self-acceptance and acceptance of others that is essential to the formation and maintenance of self-esteem. If all men were in touch with primal positive passion, the categories of gay and straight would lose their charged significance.”
	
	
[[August 10th, 2020]]
	“Time and time again when I struggled to do the work of love with a male partner who was not changing, I was told to give up on him, to kick him to the curb. I was told I was wasting my time. All this negative feedback made me ponder whether healing places exist where wounded males can go where they will not be turned away, especially when positive change is not happening fast or fast enough. Women who have been victimized by men, women who have suffered ongoing hurt at the hands of men, naturally are wisely cautious about the energy that they can expend in the service of helping men heal. Yet there are many women who have been both helped and hurt by men. Kay Leigh Hagan testifies that the good men in her life have ruined her for man hating:”
	
	
[[August 10th, 2020]]
	“For both men and women, Good Men can be somewhat disturbing to be around because they usually do not act in ways associated with typical men; they listen more than they talk; they self-reflect on their behavior and motives, they actively educate themselves about women’s reality by seeking out women’s culture and listening to women…. They avoid using women for vicarious emotional expression…. When they err—and they do err—they look to women for guidance, and receive criticism with gratitude. They practice enduring uncertainty while waiting for a new way of being to reveal previously unconsidered alternatives to controlling and abusive behavior. They intervene in other men’s misogynist behavior, even when women are not present, and they work hard to recognize and challenge their own. Perhaps most amazingly, Good Men perceive the value of a feminist practice for themselves, and they advocate it not because it’s politically correct, or because they want women to like them, or even because they want women to have equality, but because they understand that male privilege prevents them not only from becoming whole, authentic human beings but also from knowing the truth about the world…. They offer proof that men can change.”
	
	
	Notes From: hooks, bell. “The Will to Change: Men, Masculinity, and Love.” Apple Books. 

How the same above appears in Roam:

Screen Shot 2020-08-20 at 11.15.54 AM

Thanks for the comprehensive post! That kind of before and after in code blocks, as well as a Roam Research screenshot, is exactly what we need to be helpful, so I appreciate you including all that. At any rate, this does seem like it's probably a RR issue, so my ability to help any more may well be limited, but we can at least try going back to a space in front of the quotes instead of a tab, as that seemed like it worked better in the beginning. Here's a slight variation that adds spaces in front of any non-date line instead of tabs:

Format Books Highlights for Roam Research 1.2.2.kmmacros (14.2 KB)

Thank you! That one seems to be doing the same thing as the last one. But I had an idea. I formatted the notes manually and then copied out of Roam so we could see what it prefers. I didn't format the whole list of highlights. Just a couple for time sake. Here is how they come out of Roam:

- [[August 10th, 2020]]
    - “Men will never receive support from patriarchal culture for their emotional development. But if as enlightened witnesses we offer the men we love (our fathers, brothers, lovers, friends, comrades) affirmation that they can change as well as assurance that we will accept them when they are changed, transformation will not seem as risky.”
- [[August 10th, 2020]]
    - “Any woman who supports patriarchy who then claims to either love the men in her life or be frustrated that they do not love her is in a state of denial.”

So it seems it's both a series of spaces and a dash.