I’m playing around with Coda for writing, and I really like the interface so far. I have a page set up with a table to track the progress of various pieces, which are different pages within the same document. My question is: is there any way to have that table automatically grab the word count of a linked page? I’ve poked around and don’t see an obvious way to do this, but I wondered if anyone had any clever workarounds. Thanks in advance!
Its not possible to access the contents of a coda page from a formula.
(There is a way using a hidden unsupported action formula -not reccomended).
So instead I store the text for my posts in a canvas-column on a row in a table.
Each row then contains a ‘page’ of text in the canvas-column.
From a content management point of view, this works much like editing your text in a coda page.
But has the advantage that the contents can be manipulated by formulas.
For example, I can have Coda AI generate a one-line summary of my post, etc.
So if your content is in a table called POSTS
and the text is in a canvas-column called Text
then you can have a number-column called WordCount
that computes the word count with the following formula…
How it works
First we turn all the line breaks into spaces using SubstituteAll()
Then we split the text into words using Split()
Finally we count the words using the Count()
This is a niave formula that works for all practical purposes.
The more sophisticated approach is to use the regex (regular expression) approach which treats multiple ‘white space’ characters (new lines, tabs, spaces, etc) as a single word-separator.
This uses the regex code for detecting words us follows
\b
matches with any ‘blank’ characters (spaces, line feeds, tabs, etc)
\w+
matches any group of ‘word’ characters (letters and numbers)
\b
matches with the spaces after the word
the g
flag makes the regex matching ‘global’ ie; for the whole text
this results in a list of all the words in the text, which we count using the Count()
formula.
BTW:
The unsupported approach is to use the hidden formula ToHtml()
to extract the contents of a coda page into a text object (as html) and then process this to extract the text content and count the words. However this needs to be done in a BUTTON and generates lots of HTML tags that you then need to parse to get at the text content. Not reccomended.
So the best approach is to edit your text inside canvas-columns of a table, so you have formulaic access to the text. For example, I extract the forst line and display it as the title of the piece using a formula.
Max
This is extremely helpful! I’ll play around with these. Thank you!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.