Using Perfect-Markdown, tables are not rendering like GitHub's UI - swift

I'm using the Perfect framework and importing Perfect-Markdown to render my README.md on the landing page of my REST service.
Simply put, I'm attempting to render a table that looks something like:
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
My handler is:
func handler(request: HTTPRequest, response: HTTPResponse) {
response.setHeader(.contentType, value: "text/html")
let source = getSourceDir(for: #file)
let data = FileManager.init().contents(atPath: "\(source)README2.md")
let string = String.init(data: data!, encoding: .utf8)
let html = string?.markdownToHTML
response.appendBody(string: html!)
response.completed()
}
getSourceDir() is simply applying the path of the file in the project.
I really want to the table to display like it does with GitHub's UI, but instead the table displays like:
Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
zebra stripes are neat $1
There is no "table" to speak of...

Related

How to decode HTML entities in Spark-scala?

I have a spark code to read some data from a database.
One of the columns (of type string) named "title" contains the following data.
+-------------------------------------------------+
|title |
+-------------------------------------------------+
|Example sentence |
|Read the ‘Book’ |
|‘LOTR’ Is A Great Book |
+-------------------------------------------------+
I'd like to remove the HTML entities and decode it to look as given below.
+-------------------------------------------+
|title |
+-------------------------------------------+
|Example sentence |
|Read the ‘Book’ |
|‘LOTR’ Is A Great Book |
+-------------------------------------------+
There is a library "html-enitites" for node.js that does exactly what I am looking for,
but i am unable to find something similar for spark-scala.
What would be good approach to do this?
You can use org.apache.commons.lang.StringEscapeUtils with a help of UDF to achieve this.
import org.apache.commons.lang.StringEscapeUtils;
val decodeHtml = (html:String) => {
StringEscapeUtils.unescapeHtml(html);
}
val decodeHtmlUDF = udf(decodeHtml)
df.withColumn("title", decodeHtmlUDF($"title")).show()
/*
+--------------------+
| title|
+--------------------+
| Example sentence |
| Read the ‘Book’ |
|‘LOTR’ Is A Great...|
+--------------------+
*/

Filtering a table containing Hex Data in MATLAB

I currently have a table (data) containing many different data types however, I am trying to access the rows containing a certain Hex value in a column. Below is everything I have tried so far:
data=
Entry No | Time | Word
---------|-------------|-------
1 | 000:123:456 | 0123
2 | 000:123:457 | A0A0
3 | 000:123:543 | F0F0
4 | 000:124:123 | FFA0
5 | 000:124:987 | 2A0F
Msg = find(strcmp('F0F0', data.Col));
Msg = find(ismember(data.Col,'F0F0'));
Msg = strfind(data.Col, 'F0F0');
Msg = data(data{:, 20} == F0F0,:);
Due to the different datatypes in other columns I also cannot convert the table to an array.
If you have any suggestions on how I can do this, that would be great.

Column-wise autocomplete

I have a table in a PostgreSQL database with four columns that contain increasingly more detailed information (think state->city->street->number), along with a column where everything is concatenated according to some simple formatting rules. Example:
| kommun | trakt | block | enhet | beteckning |
| Mora | Gislövs Läge | 9 | 16 | Mora Gislövs Läge 9:16 |
| Mora | Gisslaved | * | 8 | Mora Gisslaved 8 |
| Mora | Gisslaved | * | 9 | Mora Gisslaved 9 |
| Lilla Edet | Sanda | GA | 1 | Lilla Edet Sanda GA:1 |
A web service uses this table to implement a word-wise autocomplete, where the user gets input suggestions as they drill down. An input of mora gis will result in
["Mora Gislövs", "Mora Gisslaved"]
Currently, this is done by splitting the concatenated column by word in this query:
select distinct trim(substring(beteckning from '(^(\S+\s?){NUMPARTS})')) as bet
from beteckning_ac
where upper(beteckning) like upper('mora gis%')
order by bet
Where NUMPARTS is the number of words in the input - 2 in this case.
Now I want the autocomplete to be done column-wise rather than word-wise, so mora gis would now result in this instead:
["Mora Gislövs Läge", "Mora Gisslaved"]
Since the first two columns can contain an arbitrary number of words, I can no longer use the input to determine how many columns to include in the response. Is there a way to do this, or have I maybe gone about this autocomplete business all wrong?
CREATE OR REPLACE FUNCTION get_auto(text)
--$1 is here your input
RETURNS setof text
LANGUAGE plpgsql
AS $function$
declare
NUMPARTS int := array_length(regexp_split_to_array($1,' '), 1);
begin
return query
select
case
when (NUMPARTS = 1) then kommun
when (NUMPARTS = 2) then kommun||' '||trakt
when (NUMPARTS = 3) then kommun||' '||trakt||' '||block
when (NUMPARTS = 4) then kommun||' '||trakt||' '||block||' '||enhet
--alter if you want to
end
from
auto_complete --your tablename here
where
beteckning like $1||'%';
end;
$function$;

Sphinx Search use_boundaries in SINPPET

I have an index rt with following configuration
index rt
{
type = rt
min_stemming_len = 4
morphology = stem_en
wordforms = /home/mis/syns.txt
exceptions = /home/mis/exp.txt
# english charset defined with alias
#charset_table = 0..9, english, _
phrase_boundary = ., ?, !
path = /var/lib/sphinxsearch/data/rt
rt_field = title
rt_field = content
rt_attr_string = content
rt_attr_string = title
rt_attr_uint = gid
}
and data in Index is
mysql> select * from rt;
+------+------+--------------------------------------------------------------------+-------+
| id | gid | content | title |
+------+------+--------------------------------------------------------------------+-------+
| 1 | 2 | This is a test with walks. Then No data shown. Wow This is fine. | test1 |
| 2 | 2 | This is a test with walks | test1 |
+------+------+--------------------------------------------------------------------+-------+
2 rows in set (0.00 sec)
I would like to get only "Wow This is fine." From rt index with snippet.
I set boundaries to the index. So that i can use the use_boundaries option for spippent. But still i am not getting the excepted result.
SELECT id, SNIPPET(content, 'wow', 'use_boundaries=1') as t FROM rt;
+------+---------------------------------------------------------------------------+
| id | t |
+------+---------------------------------------------------------------------------+
| 1 | This is a test with walks. Then No data shown. <b>Wow</b> This is fine. |
| 2 | This is a test with walks |
+------+---------------------------------------------------------------------------+
2 rows in set (0.01 sec)
any way i can use phrase_boundary to return the result by 'sentence'
Dont see any reason why use_boundaries wouldnt work.
Sounds like you also want limit_passages=1 to get just the one passage in result.
Maybe also allow_empty=1, to deal with the second document, where its been unable to highlight the query word.

Fit page height with JasperReports detail band

A report contains a unique central "Detail1" band that must fit the whole page height--even when the datasource provides just one record--the footer must remain at the bottom of the A4-sized page:
_______________
| header |
| |
| row1 |
| row2 |
| |
| |
| |
| |
| |
| footer |
|_______________|
YES!
_______________
| header |
| |
| row1 |
| row2 |
| footer |
|_______________|
NO!
I wonder whether this is related to the "stretching" options or to the background.
We also have this more general problem of vertically sizing some band or content relative to the page height.
In your case it could be done, e.g. by either increasing the row2 "bottom margin" or the footer "top margin" (or introducing some "spacer element" inbetween):
variant A variant B variant C
___________ __________ __________
| header | | header | | header |
|_________| |________| |________|
| row1 | | row1 | | row1 |
|_________| |________| |________|
| row2 | | row2 | | row2 |
| . | |________| |________|
| . | | . | | spacer |
|_________| | . | |________|
| footer | | footer | | footer |
|_________| |________| |________|
The only way I currently can think of to solve this, is kind of a hack, if "you know enough about the size of the to-be-streched element siblings":
We want to set the spacer.height (or margin depending on the variant chosen) like this:
spacer.height = page.height - header.height - row1.height - row2.height - footer.height
Example A
Let's assume for simplicity of this example that
only row2.height is flexible (~ dynamic)
for simplicity let's say row2.height is made of numbers separated by linefeeds like this:
17
2
34
Using variant A we could manually test, after how many linefeeds/numbers the footer would be pushed on the next page, let's say 5.
So all we would have to do is to
either dynamically adjust the bottom margin of row2 to max( 0, 5 - row2LinefeedsCount * row2lineHeight ) (e.g. via Groovy or Java)
or if it is based on some SQL select, fill in some blank space lines like this:
-- (Oracle SQL)
select
...,
dyn_row2_col
-- add additional linefeeds if necessary (when < 5 lines)
-- (counts by the content length after removing all digits)
|| lpad(
'',
max( 0, 5 - length( regexp_replace( dyn_row2_col, '\d', '' ))),
CHR(13) )
as dyn_row2_col,
...
from ...
Example B
Another example could be, that row2s height is dependent and linearly increased by the number of subrows of some query result (e.g. if it is a simple subreport with equally sized rows). Then we could maybe use variant C and fill the spacer (invisibly) with some dummy query based on the subrow query (and doing the calculation of the rest space similar to the above example).
search engine tags/phrases
fit band height to page size/height, band height 100% of page size, max-height, stretch vertically to 100% parent container height or page size
implementation/usage thoughts of Jasper Reports
I find it a pain to not be easily able to use flexible positioning/sizing expressions (e.g. to let the footer stick to the bottom, float elements horizontally (e.g. table columns) or spacer.height: 75%) with Jasper Reports in this modern flex layout HTML/responsive layout world. The absolut positioning philosophy should be enhanced here. Eclipse BIRT is much better at this, but has other disadvantages. Of course the implementation could be quite complex, more memory intense and slower, but I think the benefit in non-absolute positioning requirement scenarios would be great.
I wrote some general Scriptlet (I plan to provide in jasper-utils), which solves the floating of horizontal columns based on named component styles (similar to CSS classes) on related columns. It behaves very similar to HTML tables, using the available horizontal space based on column-specific percentage and "underflow-stretch-calc" expressions and the possiblity to show/hide columns (over all related bands).